當前位置:編程學習大全網 - 源碼下載 - IOS uiview 的切換

IOS uiview 的切換

添加庫文件:QuartzCore.framework

創建兩個view和壹個button

- (void)viewDidLoad

{

[super viewDidLoad];

UIView* view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];

view1.backgroundColor = [UIColor redColor];

[self.view addSubview:view1];

[view1 release];

UIView* view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];

view2.backgroundColor = [UIColor blueColor];

[self.view addSubview:view2];

[view2 release];

UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

button.frame = CGRectMake(100, 100, 100, 30);

[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button];

}

//----------------------------------------------------------------------------------------------------

動畫

- (void)buttonClick{

CATransition* transition = [CATransition animation];

//只執行0.5-0.6之間的動畫部分

// transition.startProgress = 0.5;

// transition.endProgress = 0.6;

//動畫持續時間

transition.duration = 2.0;

//進出減緩

transition.timingFunction = UIViewAnimationCurveEaseInOut;

//動畫效果

transition.type = @"pageCurl";

transition.subtype = kCATransitionFromBottom;

transition.delegate = self;

[self.view.layer addAnimation:transition forKey:nil];

//view之間的切換

[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

//---------------------------------------------------------------------------------------------------------

//動畫開始調用此函數

- (void)animationDidStart:(CAAnimation *)anim{

NSLog(@"begin");

}

//動畫結束調用此函數

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{

CATransition* transition = [CATransition animation];

transition.duration = 2.0;

transition.timingFunction = UIViewAnimationCurveEaseInOut;

transition.type = @"pageUnCurl";

transition.subtype = kCATransitionFromBottom;

[self.view.layer addAnimation:transition forKey:nil];

[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

}

//--------------------------------------------------------------------------------------------------------

不添加類庫的方法

- (void)buttonClick{

[UIView beginAnimations:nil context:nil];

//持續時間

[UIView setAnimationDuration:4.0];

//在出動畫的時候減緩速度

[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

//添加動畫開始及結束的代理

[UIView setAnimationDelegate:self];

[UIView setAnimationWillStartSelector:@selector(begin)];

[UIView setAnimationDidStopSelector:@selector(stopAni)];

//動畫效果

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

[UIView commitAnimations];

}

- (void)begin{

NSLog(@"begin");

}

- (void)stopAni{

NSLog(@"stop");

}

  • 上一篇:來邦IP網絡ATM機求助可視對講
  • 下一篇:夢見切很多水果。
  • copyright 2024編程學習大全網