ScrollView and Image Move Sample


//
//  nemesisViewController.h
//  viewTest
//
//  Created by  on 12. 1. 17..
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface nemesisViewController : UIViewController {
    UIView *backView, *displayView;
    UIScrollView *scView;
    UIProgressView *progress;
    CGFloat init_x;
}

@property (nonatomic, retain) IBOutlet UIView *backView;
@property (nonatomic, retain) IBOutlet UIView *displayView;
@property (nonatomic, retain) IBOutlet UIScrollView *scView;
@property (nonatomic, retain) IBOutlet UIProgressView *progress;

@end


//
//  nemesisViewController.m
//  viewTest
//
//  Created by  on 12. 1. 17..
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "nemesisViewController.h"

@implementation nemesisViewController

@synthesize backView, displayView, scView, progress;

- (void)didReceiveMemoryWarning
{
    NSLog(@"didReceiveMemoryWarning");
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    NSLog(@"viewDidLoad");
    [super viewDidLoad];

    UIImage *image = [UIImage imageNamed:@"bar.png"];
    UIImageView *imageview = [[UIImageView alloc] initWithImage:image];

    [scView addSubview:imageview];
    init_x = scView.bounds.origin.x;
    
    // 180(M_PI), 270(M_PI + (M_PI_2) invert
    progress.transform = CGAffineTransformMakeRotation(M_PI);
    progress.progressTintColor = [UIColor redColor];
    progress.progress = 0.0f;

    // repeat 1 second 
    [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(handleTimer:) userInfo:nil repeats:YES];
    
}

-(void)handleTimer:(NSTimer *)timer {
    NSLog(@"progress:%.2f", progress.progress);
    if (progress.progress >= 1.0f) {
        progress.progress = 0.0f;
    } else {
        progress.progress = progress.progress + 0.01f;
    }
    
    NSLog(@"x:%f", scView.bounds.origin.x);
    CGRect bounds;
    bounds = scView.bounds;
    if (fabsf(scView.bounds.origin.x) < (scView.bounds.size.width - 20)) {
        bounds = CGRectMake(scView.bounds.origin.x - 1.0f, scView.bounds.origin.y, scView.bounds.size.width, scView.bounds.size.height);
    } else {
        bounds = CGRectMake(init_x, scView.bounds.origin.y, scView.bounds.size.width, scView.bounds.size.height);
    }
    scView.bounds = bounds;    
    
}

- (void)viewDidUnload
{
    NSLog(@"viewDidUnload");
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.backView = nil;
    self.displayView = nil;
    self.scView = nil;
    self.progress = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    NSLog(@"viewWillAppear");
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"viewDidAppear");
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    NSLog(@"viewWillDisappear");
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    NSLog(@"viewDidDisappear");
[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    NSLog(@"rotate message");
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

댓글

이 블로그의 인기 게시물

한글 2010 에서 Ctrl + F10 누르면 특수문자 안뜰 때

아이폰에서 RFID 사용하는 방법

맥 화면이 안나올때 조치방법