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

在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];
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值