設置UIImageView
_imageAime = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 100, 100)];
_imageAime.image =[UIImage imageNamed:@"icon_baiban"];
[self.view addSubview:_imageAime];
//縮放效果
-(void)Zoom{
[UIView animateWithDuration:3 animations:^{ //動畫的邏輯 _imageAime.frame =CGRectMake(10, 200, 300, 250); } completion:^(BOOL finished) { //動畫結束之后要執行的代碼 //重開了一個UIView動畫,還原位置 [UIView animateWithDuration:3 animations:^{ _imageAime.frame =CGRectMake(50, 100, 100, 100); }]; }];
}
//旋轉效果
-(void)rotation{
CABasicAnimation *basianimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//設置時長
[basianimation setDuration:10];
//重復次數
[basianimation setRepeatCount:2];
//所改變屬性的起始值
basianimation.fromValue = [NSNumber numberWithDouble:2];
//所改變屬性的結束時的值
basianimation.toValue = [NSNumber numberWithDouble:M_PI * 20]; [_imageAime.layer addAnimation:basianimation forKey:nil];
//動畫結束時是否執行逆動畫
basianimation.autoreverses = YES;
}
//虛化效果
-(void)grammaticalization{
//第三種UIView動畫的另一種寫法(沒有block) [UIView beginAnimations:@"view動畫的另一種寫法" context:nil]; //設置時長 [UIView setAnimationDuration:1]; //設置重復次數 [UIView setAnimationRepeatCount:NSIntegerMax]; //動畫的邏輯 _imageAime.alpha =0.4; //結束動畫 [UIView commitAnimations];
}
//
-(void)tremble{
//2,延時時間(等待)3,顫抖效果,值越小,抖動的越厲害 4,開始時的動畫速度,值越大速度越快 [UIView animateWithDuration:2 delay:1 usingSPRingWithDamping:0.2 initialSpringVelocity:3 options:UIViewAnimationOptionCurveEaseInOut animations:^{ _imageAime.frame =CGRectMake(100, 400, 300, 250); } completion:^(BOOL finished) { }];
}
-(void)curve{
//關鍵幀動畫 CAKeyframeAnimation *keyanimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; //創建一個路徑, 用來記錄每一幀 CGMutablePathRef path = CGPathCreateMutable(); //指定移動的起點 CGPathMoveToPoint(path, NULL, _imageAime.center.x, _imageAime.center.y); //畫一條曲線(貝塞爾曲線) CGPathAddCurveToPoint(path, NULL, 100, 100, 370, 320, 100, 690); //設置路徑 [keyanimation setPath:path]; //設置時間 [keyanimation setDuration:3]; //設置重復次數 [keyanimation setRepeatCount:1]; [_imageAime.layer addAnimation:keyanimation forKey:@"keyanimation" ];
}
新聞熱點
疑難解答