2011년 5월 18일 수요일

이미지 슬라이드

/  SampleDay3_1ViewController.m
//  SampleDay3-1
//
//  Created by bit on 11. 5. 18..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SampleDay3_1ViewController.h"

@implementation SampleDay3_1ViewController
@synthesize imageView;
@synthesize timer;


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
 [super loadView];
 //.. 
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
//UIImage *image = [UIImage imageNamed:@"Background_0.jpg"];
// [self.imageView setImage:image];
//
idx = 0;
[self loadImageByIndex:idx];

}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

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

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


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.imageView = nil;
}


- (void)dealloc {
    [super dealloc];
}

- (IBAction)onPrevious:(id)sender
{
if ( --idx < 0 ) {
idx = 5;
}
[self loadImageByIndex:idx];
}
- (IBAction)onNext:(id)sender
{
if (++idx > 5 ) {
idx = 0;
}
[self loadImageByIndex:idx];
}
- (IBAction)onSwitchChanged:(id)sender
{
UISwitch *sw = (UISwitch *)sender;
NSLog(@"onSwitchChanged");
if ( sw.on == YES) {
// NSTimer *_timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(onTimerCallback:) userInfo:nil repeats:YES ];
NSTimer *_timer1 = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(onTimerCallback:) userInfo:nil repeats:YES]; 
   
NSLog(@"sw.on YES");
self.timer = _timer1;
}
else {
NSLog(@"sw.on NO");
}
}


- (void)onTimerCallback:(NSTimer *)_timer
{
[self onNext:nil];
NSLog(@"Timer");
}

- (void)loadImageByIndex:(NSInteger)index
{
NSString *imageName = [NSString stringWithFormat:@"Background_%d.jpg", index];
UIImage *image = [UIImage imageNamed:imageName];
[self.imageView setImage:image];
}


@end

댓글 없음:

댓글 쓰기

참고: 블로그의 회원만 댓글을 작성할 수 있습니다.