您的位置:首页 > 产品设计 > UI/UE

使用block创建UIView animation动画效果(包含常用几种方法)

2011-06-10 11:56 579 查看
使用Block 创建

-(void)showBuyNowView
{
NSArray* arrViews = [[NSBundle mainBundle] loadNibNamed:@"BuyNowView" owner:self options:0];
NMBuyNowVeiw* buy = [arrViews objectAtIndex:0];
_buyNowView = buy;
buy.frame = CGRectMake(0, 500, 320, 20);
[self.view addSubview:buy];

[UIView animateWithDuration:0.2
delay:0
options: UIViewAnimationCurveEaseOut
animations:^{
//[UIView setAnimationTransition:transition forView:buy.superview cache:YES];

buy.frame = CGRectMake(0, 380, 320, 20);
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];

}


不使用block

(1)

[UIView beginAnimations:@"Curl"context:nil];//动画开始
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myview cache:YES];   [myview removeFromSuperview];
[UIView commitAnimations];


(2)

CATransition *animation = [CATransition animation];
[animation setDuration:1.25f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setType:kCATransitionReveal];
[animation setSubtype: kCATransitionFromBottom];
[self.view.layer addAnimation:animation forKey:@"Reveal"];


这里使用了setType与setSubtype组合,这使用个比较保险,因为他的参数就是官方API里定义的,他们的参数说明可以参考如下:

(3)最后再给出一种常用代码

// Curl the image up or down

CATransition *animation = [CATransition animation];
[animation setDuration:0.35];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];

if (!curled)
{
//animation.type = @"mapCurl";
animation.type = @"pageCurl";
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 0.99;
} else {
//animation.type = @"mapUnCurl";
animation.type = @"pageUnCurl";
animation.fillMode = kCAFillModeBackwards; animation.startProgress = 0.01;
}

[animation setRemovedOnCompletion:NO];
[view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[view addAnimation:animation forKey"pageCurlAnimation"];
// Disable user interaction where necessary

if (!curled) {
}

else {

}

curled = !curled;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: