2011년 5월 25일 수요일

iphone UIView 애니메이션 적용하기

//
//  SampleDay8_1ViewController.h
//  SampleDay8-1
//
//  Created by bit on 11. 5. 25..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#define kSegmentedControlTag 11
#define kBgViewTag 100
#define kWhiteViewTag 101
#define kGrayViewTag 102

#import

@interface SampleDay8_1ViewController : UIViewController {

}

@end



//
//  SampleDay8_1ViewController.m
//  SampleDay8-1
//
//  Created by bit on 11. 5. 25..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SampleDay8_1ViewController.h"

@interface SampleDay8_1ViewController (Private) 

-(IBAction)segmentValueChanged:(id)sender;

@end



@implementation SampleDay8_1ViewController



/*
// 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 {
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
UISegmentedControl *segment = (UISegmentedControl*)[self.view viewWithTag:kSegmentedControlTag];
[segment addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
}


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

- (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;
}


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

-(IBAction)segmentValueChanged:(id)sender {

NSLog(@"call segmentValueChanged() -- value = ");

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.5f];
UIView *bgView = [self.view viewWithTag:kBgViewTag];
UISegmentedControl *segmentControl = (UISegmentedControl*)sender;
switch (segmentControl.selectedSegmentIndex) {
case 0:
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:bgView cache:YES];
break;
case 1:
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:bgView cache:YES];
break;
case 2:
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:bgView cache:YES];
break;
case 3:
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:bgView cache:YES];
break;
default:
break;
}
NSInteger whiteViewIndex = [bgView.subviews indexOfObject:[bgView viewWithTag:kWhiteViewTag]];
NSInteger grayViewIndex = [bgView.subviews indexOfObject:[bgView viewWithTag:kGrayViewTag]];
[bgView exchangeSubviewAtIndex:whiteViewIndex withSubviewAtIndex:grayViewIndex];
[UIView commitAnimations];
}


@end




댓글 없음:

댓글 쓰기

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