標籤:
初學ios開發,很多概念還不清楚,所以只有邊學邊做例子。又怕學了後面忘了前面,因此用自己的部落格來紀錄自己的學習曆程,也是對自己學習不要懈怠做個監督。
剛學ios做動畫效果。因為ios封裝得很好,實現ios的漂亮動畫效果也很簡單,卻因為我自己的粗心落了一個字母 導致糾結了一天,這個教訓必須記住,同時也懂得了調試技能在編程裡地位也是非常重要的存在。
實現ios動畫有兩種方法:一種UIView層面的,一種是使用CATransition.
[objc] view plaincopy
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- UIView *redView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- redView.backgroundColor = [UIColor redColor];
- [self.view addSubview:redView];
-
- UIView *yellowView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- yellowView.backgroundColor = [UIColor yellowColor];
- [self.view addSubview:yellowView];
-
- UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [button setTitle:@"改變1" forState:UIControlStateNormal];
- button.frame = CGRectMake(10, 10, 300, 40);
- [button addTarget:self action:@selector(changeUIView1) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:button];
-
-
-
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [button2 setTitle:@"改變2" forState:UIControlStateNormal];
- button2.frame = CGRectMake(10, 120, 300, 40);
- [button2 addTarget:self action:@selector(changeUIView2) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:button2];
- }
- -(void) changeUIView1{
- [UIView beginAnimations:@"animation" context:nil];
- [UIView setAnimationDuration:1.0f];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
- [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0 ];
- [UIView commitAnimations];
- }
-
- -(void) changeUIView2{
- CATransition *transition = [CATransition animation];
- transition.delegate = self;
- transition.duration = 2.0f;
- transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
- transition.type = kCATransitionPush;
- transition.type = @"pageCurl" ;//另一種設定動畫效果方法
- transition.subtype = kCATransitionFromBottom;
- [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
- [self.view.layer addAnimation:transition forKey:@"animation"];
- }
調用CATransition需要在frameworks中添加QuartzCore.framework,在.h檔案中加入 #import <QuartzCore/QuartzCore.h>
setType:有四種類型:
kCATransitionFade //交叉淡化過渡
kCATransitionMoveIn //移動覆蓋原圖
kCATransitionPush //新視圖將舊視圖推出去
kCATransitionReveal //底部顯出來
另一種設定方法
pageCurl //向上翻一頁
pageUnCurl //向下翻一頁
rippleEffect //滴水效果
suckEffect //收縮效果,如一塊布被抽走
cube //立方體效果
oglFlip //上下翻轉效果
setSubtype:有四種類型:
kCATransitionFromRight;
kCATransitionFromLeft(預設值)
kCATransitionFromTop;
kCATransitionFromBottom
ios 動畫效果CATransition筆記