UIImageView實現縮放特效動畫

 

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSArray *animationImages = @[
                                 [UIImage imageNamed:@"1.jpg"],
                                 [UIImage imageNamed:@"2.jpg"],
                                 [UIImage imageNamed:@"3.jpg"],
                                 [UIImage imageNamed:@"4.jpg"]
                                 ];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 300)];
    imageView.animationImages = animationImages ;
    imageView.animationRepeatCount = 0;
    imageView.animationDuration= 12.0;
    [imageView startAnimating];
    [self.view addSubview:imageView];
    
    // 當圖片改變時呼叫執行動畫的 method => scaleView:
    [[NSTimer scheduledTimerWithTimeInterval:12.0/animationImages.count
                                      target:self
                                    selector:@selector(scaleView:)
                                    userInfo:@{
                                               @"view": imageView
                                               }
                                     repeats:YES] fire];
}

- (void)scaleView:(NSTimer *)timer {
    UIImageView *view = [timer.userInfo objectForKey:@"view"];
    view.frame = CGRectMake(150, 150, 20, 20);
    CGPoint center = view.center;
    [UIView animateWithDuration: 1.0f
                     animations:^{
                         view.frame = CGRectMake(10, 10, 300, 300);
                         view.center = center;
                     }];
    
}
@end

 

 

arrow
arrow
    創作者介紹
    創作者 Will 的頭像
    Will

    Will的部落格

    Will 發表在 痞客邦 留言(0) 人氣()