(转) iphone使用中的动画效果之loading效果和界面切换效果

(转) iphone应用中的动画效果之loading效果和界面切换效果
在应用开发中总要用到加载数据时候的loading动画效果 以下为一个loading效果实例,可以直接拿去用的:

在你的xxxController 头文件中声明: UIView *colorView;

UIActivityIndicatorView *aciv;

初始化中定义: aciv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; colorView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];

[colorView setBackgroundColor:[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.4]];

加入以下方法:

- (void)addLoading{

aciv.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhite;

aciv.center=CGPointMake(screenWidth/2,screenHeight/2-10);

[self.view addSubview:colorView];

[aciv startAnimating];

[self.view addSubview:aciv];

}

- (void)removeLoading{

[colorView removeFromSuperview];

[aciv stopAnimating];

[aciv removeFromSuperview];

}

注释掉 //[self.view addSubview:colorView];

//[colorView removeFromSuperview];

则动画没有灰色背景 界面切换则可以有很多效果,如淡入淡出,放大,雾化,翻转等。 淡入淡出:

- (void)animateEaseInEaseOut:(CALayer*)laye delegate:(id)del{

CATransition *animationA = [CATransition animation];

[animationA setType:kCATransitionFade];

[animationA setDuration:1];

[animationA setDelegate:del];

[animationA setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [laye addAnimation:animationA forKey:@"EaseInEaseOut"];

}

翻转:

- (void)animateFlipView{

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:1];

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

[UIView commitAnimations];

}