您的位置:首页 > 移动开发 > IOS开发

iOS启动页面多张图片自动切换(带动画效果)

2016-08-15 22:52 555 查看
在AppDelegate.m中首先封装一段利用CATransition设置动画的代码

- (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIView *) view{
//创建CATransition对象
CATransition *animation = [CATransition animation];
//设置运动时间
animation.duration = 2.0;
//设置运动type
animation.type = type;
if (subtype != nil) {
//设置子类
animation.subtype = subtype;
}
//设置运动速度
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
[view.layer addAnimation:animation forKey:@"animation"];
}


然后我们在AppDelegate.h中声明一个UIImageView的属性

@property (strong, nonatomic) UIImageView *splashView;


之后在AppDelegate.m的didFinishLaunchingWithOptions方法中设置图片:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
self.splashView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[self.splashView setImage:[UIImage imageNamed:@"welcome0"]];
[self.window addSubview:self.splashView];
[self.window bringSubviewToFront:self.splashView];
[self performSelector:@selector(showTheFirstImage) withObject:nil afterDelay:2.0f];
[self performSelector:@selector(showTheSecondImage) withObject:nil afterDelay:5.0f];
[self performSelector:@selector(showTheThirdImage) withObject:nil afterDelay:8.0f];
return YES;
}


然后就是三个显示图片的方法:

-(void)showTheFirstImage{
//波纹效果
[self transitionWithType:@"rippleEffect" WithSubtype:kCATransitionFromBottom ForView:self.splashView];
/** 运动方向
kCATransitionFromRight
kCATransitionFromLeft
kCATransitionFromTop
kCATransitionFromBottom
*/
[self.splashView setImage:[UIImage imageNamed:@"welcome1"]];
}

-(void)showTheSecondImage{
//淡化效果
[self transitionWithType:kCATransitionFade WithSubtype:kCATransitionFromBottom ForView:self.splashView];
[self.splashView setImage:[UIImage imageNamed:@"welcome2"]];
}

-(void)showTheThirdImage{
//翻页效果
[self transitionWithType:@"pageCurl" WithSubtype:kCATransitionFromBottom ForView:self.splashView];
[self.splashView setImage:[UIImage imageNamed:@"welcome3"]];
}


一些动画效果如下:

//淡化效果
[self transitionWithType:kCATransitionFade WithSubtype:subtypeString ForView:self.view];
//push效果
[self transitionWithType:kCATransitionPush WithSubtype:subtypeString ForView:self.view];
//揭开效果
[self transitionWithType:kCATransitionReveal WithSubtype:subtypeString ForView:self.view];
//覆盖效果
[self transitionWithType:kCATransitionMoveIn WithSubtype:subtypeString ForView:self.view];
//立方体效果
[self transitionWithType:@"cube" WithSubtype:subtypeString ForView:self.view];
//吮吸效果
[self transitionWithType:@"suckEffect" WithSubtype:subtypeString ForView:self.view];
//翻转效果
[self transitionWithType:@"oglFlip" WithSubtype:subtypeString ForView:self.view];
//波纹效果
[self transitionWithType:@"rippleEffect" WithSubtype:subtypeString ForView:self.view];
//翻页效果
[self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
//反翻页效果
[self transitionWithType:@"pageUnCurl" WithSubtype:subtypeString ForView:self.view];
//相机打开效果
[self transitionWithType:@"cameraIrisHollowOpen" WithSubtype:subtypeString ForView:self.view];
//相机关闭效果
[self transitionWithType:@"cameraIrisHollowClose" WithSubtype:subtypeString ForView:self.view];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息