iOS实现翻页效果动画

项目里面有一个接受消息然后将消息内容以翻页的形式展现给用户,返回的数据就是简单的文字没有图片,所以我就简单的用了textView接收然后在view上设置了翻页效果的切换动画,这个翻页切换也比较简单,就是用了一下系统的动画.
效果如图:


PageBlurTestGif.gif

大体思路:
在self.view 上放置一个label,label.text从数组中获得,当点击上下页按钮的时候,改变label.text,并且执行翻页效果动画.

主要代码:

#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动画实现
/**
 *  动画效果实现
 *
 *  @param type    动画的类型 在开头的枚举中有列举,比如 CurlDown//下翻页,CurlUp//上翻页
,FlipFromLeft//左翻转,FlipFromRight//右翻转 等...
 *  @param subtype 动画执行的起始位置,上下左右
 *  @param view    哪个view执行的动画
 */
- (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"];
}

主要就是熟悉一下简单动画的实现了
本项目gitHub地址:https://github.com/irembeu/PageBlurDemo.git

//2 添加启动页和手势控制的翻页效果实现,添加swipe手势后画面切换更生动.
效果图:


PageBlurTestGif.gif
#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 分支中.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,134评论 25 709
  • WebSocket-Swift Starscream的使用 WebSocket 是 HTML5 一种新的协议。它实...
    香橙柚子阅读 24,176评论 8 184
  • 你轧过历史的辙印 多得象一团麻 绵来绕去 把中国 悬在一只吊床上 悠悠千载 老人家 是否在 整理《论语》 ...
    子心yjr一广州阅读 333评论 0 3
  • 念你着了魔, 嗔你太情薄。 如何才能不念你, 佛说最苦痴情人。 你在花季中走过, 我却用余生念你。
    瀚辰阅读 204评论 0 0
  • 爱,是为了促进自己和他人心智成熟,而不断拓展自我界限,实现自我完善的一种愿望。 真正的爱是行动,是一种由意愿而产生...
    芥末丫丫阅读 263评论 0 0