CATransition Demo

#import "TRViewController.h"

@interface TRViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *mySV;
@property (nonatomic)int index;
@end

@implementation TRViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    for (int i=0; i<5; i++) {
        NSString *imageName = [NSString stringWithFormat:@"%d.jpg",i];
        UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(i*320, 0, 320, self.view.bounds.size.height)];
        iv.image = [UIImage imageNamed:imageName];
        [self.mySV addSubview:iv];
    }
    
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changeImageAction) userInfo:Nil repeats:YES];
    
    
}
-(void)changeImageAction{
    //     fade moveIn  push  reveal
    //    cube suckEffect oglFlip rippleEffect pageCurl pageUnCurl cameraIrisHollowOpen cameraIrisHollowClose
    NSArray *typeArr = @[@"pageCurl",@"rippleEffect",@"oglFlip",@"cube",@"suckEffect"];
    
    CATransition *animation = [CATransition animation];
    animation.type = typeArr[arc4random()%typeArr.count];
    animation.subtype = @"fromLeft";
    animation.duration = 1;
    animation.delegate = self;
    [self.mySV.layer addAnimation:animation forKey:Nil];
    [self.mySV setContentOffset:CGPointMake(320*(++self.index%5), 0)];
}


- (void)animationDidStart:(CAAnimation *)anim{
    NSLog(@"动画开始");
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
      NSLog(@"动画结束");
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}

@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值