iOS實現(xiàn)翻頁效果動畫實例代碼
大體思路:
在self.view 上放置一個label,label.text從數(shù)組中獲得,當點擊上下頁按鈕的時候,改變label.text,并且執(zhí)行翻頁效果動畫.
效果如圖:

主要代碼:
#pragma mark - 下一頁按鈕響應事件
- (void)nextPage:(UIButton *)btn {
_forwardBtn.enabled = YES;
if (_count<_arr.count-1) {
btn.enabled = YES;
_label.text = [_arr objectAtIndex:_count+1];
NSString *subtypeString;
subtypeString = kCATransitionFromRight;
[self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
_count = _count + 1;
} else {
_count = _arr.count - 1;
btn.enabled = NO;
[self showAlert:@"已經是最后一頁咯,親(づ ̄ 3 ̄)づ"];
}
NSLog(@"%ld", (long)_count);
}
#pragma CATransition動畫實現(xiàn)
/**
* 動畫效果實現(xiàn)
*
* @param type 動畫的類型 在開頭的枚舉中有列舉,比如 CurlDown//下翻頁,CurlUp//上翻頁
,FlipFromLeft//左翻轉,FlipFromRight//右翻轉 等...
* @param subtype 動畫執(zhí)行的起始位置,上下左右
* @param view 哪個view執(zhí)行的動畫
*/
- (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIView *) view {
CATransition *animation = [CATransition animation];
animation.duration = 0.7f;
animation.type = type;
if (subtype != nil) {
animation.subtype = subtype;
}
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
[view.layer addAnimation:animation forKey:@"animation"];
}
主要就是熟悉一下簡單動畫的實現(xiàn)了
本項目gitHub地址:https://github.com/iOSJason/PageBlurDemo.git
2 添加啟動頁和手勢控制的翻頁效果實現(xiàn),添加swipe手勢后畫面切換更生動.
效果圖:

#pragma mark - 手勢
- (void)configTapGes {
_fromRightSwip = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(nextPage:)];
_fromRightSwip.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:_fromRightSwip];
_fromLeftSwip = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(forwardPage:)];
_fromLeftSwip.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:_fromLeftSwip];
}
//判斷是否是第一次進入程序
if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"isFirst"] isEqualToString:@"yes"]) {
//顯示提示
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"tishi" message:@"" delegate:self cancelButtonTitle:@"曉得了" otherButtonTitles: nil];
[alert show];
[[NSUserDefaults standardUserDefaults]setObject:@"yes" forKey:@"isFirst"];
}
動畫效果和上一個是一種效果,具體代碼請看我的gibHub,和上一個項目在一個地址里面,這個在 SwipeGesturePageBlurDemo 分支中.
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
iOS實現(xiàn)漸變按鈕Gradient Button的方法示例
這篇文章主要給大家介紹了關于iOS實現(xiàn)漸變按鈕Gradient Button的相關資料,文中通過示例代碼介紹的非常詳細,對各位iOS開發(fā)者們具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-08-08
iOS NSURLSessionDownloadTask設置代理文件下載的示例
本篇文章主要介紹了iOS NSURLSessionDownloadTask設置代理文件下載的示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01
IOS TextFiled與TextView 鍵盤的收起以及處理鍵盤遮擋
這篇文章主要介紹了IOS TextFiled與TextView 鍵盤的收起以及處理鍵盤遮擋的相關資料,需要的朋友可以參考下2016-12-12
iOS應用開發(fā)中對UIImage進行截取和縮放的方法詳解
這篇文章主要介紹了iOS應用開發(fā)中對UIImage進行截取和縮放的方法,分別講解了如何截取指定區(qū)域大小的UIImage以及縮放到指定大小和等比縮放的具體操作過程,需要的朋友可以參考下2016-04-04

