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
文章標籤
全站熱搜
留言列表