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

ios 组合动画实现图片浏览,效果为图片放大并淡出

2014-08-12 14:27 579 查看
//声明变量
@property (strong,
nonatomic) IBOutlet UIImageView *viewToAnimate;//由storyboard引出
@property (strong,
nonatomic) NSMutableArray * array;
@property (assign,
nonatomic) NSInteger currentNum;
- (void)viewDidLoad
{
    [superviewDidLoad];
//添加图片资源
    _array = [[NSMutableArrayalloc]initWithObjects:@"flower1.jpg",@"flower2.jpg",@"flower3.jpg",@"flower4.jpg",@"flower5.jpg",nil];
    [self.viewToAnimatesetImage:[UIImageimageNamed:_array[0]]];
//设置图片循环播放的timer
     [NSTimerscheduledTimerWithTimeInterval:(4.0f)target:selfselector:@selector(beginToplay)userInfo:nilrepeats:YES];
}
//图片播放的动画效果,放大并淡出
- (void)beginToplay
{
    [self.viewToAnimatesetImage:[UIImageimageNamed:_array[_currentNum]]];
    [UIViewanimateWithDuration:1
                          delay:1
                        options:UIViewAnimationOptionCurveEaseOutanimations:^(void){
                            self.viewToAnimate.alpha =0.0;
                            self.viewToAnimate.frame =CGRectMake(10,20,300,650);
                        }completion:^(BOOL finished){
                            [UIView
animateWithDuration:.0
                                                 
delay:0.5
                                               
options:UIViewAnimationOptionTransitionCrossDissolve
                                             animations:^(void){
                                                 _currentNum ++;
                                                 if(_currentNum == [_arraycount])
                                                 {
                                                    
_currentNum = 0;
                                                 }
                                                 [self.viewToAnimatesetImage:[UIImage
imageNamed:_array[_currentNum]]];
                                                 self.viewToAnimate.alpha =1.0;
                                                 self.viewToAnimate.frame =CGRectMake(60,
18,200, 450);
                                             }completion:^(BOOL finished){
                                             }];
                            
                        }];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  图片 动画 iOS