使用Swift实现部分页面翻页动画

5
我正在寻找一种在UIView上指示页面翻页动画的方法,以提示用户可以滚动浏览多个页面。这应该是一种部分页面翻页效果。
问题在于我不知道如何实现。我找到了一些教程,但只适用于Objective-C,我不知道如何将其转换为Swift:
 [UIView animateWithDuration:1.0
                     animations:^{
                         CATransition  * animation = [CATransition animation];
                         [animation setDuration:1.2f];
                         animation.startProgress = 0.0;
                         animation.endProgress   = 0.6;
                         [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
                         [animation setType:@"pageCurl"];
                         [animation setSubtype:@"fromRight"];
                         [animation setRemovedOnCompletion:NO];
                         [animation setFillMode: @"extended"];
                         [animation setRemovedOnCompletion: NO];
                         [[self.animatedUIView layer] addAnimation:animation
                                                      forKey:@"pageFlipAnimation"];
                          [self.animatedUIView addSubview:tempUIView];

                     }
     ];

http://www.iostute.com/2015/04/how-to-implement-partial-and-full-page.html

3个回答

8
UIView.animate(withDuration: 1.0, animations: {
    let animation = CATransition()
    animation.duration = 1.2
    animation.startProgress = 0.0
    animation.endProgress = 0.6
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
    animation.type = "pageCurl"
    animation.subtype = "fromRight"
    animation.isRemovedOnCompletion = false
    animation.fillMode = "extended"
    self.animatedUIView.layer.add(animation, forKey: "pageFlipAnimation")
    self.animatedUIView.addSubview(tempUIView)
})

2

为了帮助您,我已将同一代码更新到最新版本

UIView.animate(withDuration: 1.0, animations: {
        let animation = CATransition()
        animation.duration = 1.2
        animation.startProgress = 0.0
        animation.endProgress = 0.6
        animation.type = CATransitionType(rawValue: "pageCurl")
        animation.subtype = CATransitionSubtype(rawValue: "fromRight")
        animation.isRemovedOnCompletion = false
        animation.fillMode = CAMediaTimingFillMode(rawValue: "extended")
        animation.isRemovedOnCompletion = false
        if let animation = animation as? CATransition{
            self.view.layer.add(animation, forKey: "pageFlipAnimation")
            self.viewDidLoad()
        }
        self.view.addSubview(self.TableView)
    })

@Leena,我已经调用了viewDidLoad方法,因为我正在同一页上加载另一组数据。你可以根据自己的选择进行修改。 - Raghav Chopra

0

我已经完成了这个。现在我想在第一页上添加一个预告,向用户展示还有更多页面可以滚动查看。就像右下角有一个小边缘稍微卷曲的提示。 - Patricks
我明白你的意思。在我的项目中,我使用带有卷曲图像背景的UIButton,当用户按下该按钮时,它将触发卷曲动画。 - rohit90

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接