Partial pagecurl animation with swift
Asked Answered
P

3

5

I'm looking for a way to indicate a pagecurl animation on an uiview to give the user a hint that he can scroll through some pages. It should be some kind of partial pagecurl.

The problem is that I don't know how to do that. I found some tutorials but only for objective c and I don't know how transfer it into 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

Pleasance answered 21/9, 2016 at 12:42 Comment(0)
M
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)
})
Molybdenous answered 21/9, 2016 at 13:22 Comment(0)
T
2

For your help I have uppdatedt the same code to the latest version

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)
    })
Trotta answered 25/2, 2020 at 12:23 Comment(1)
@Leena I have called viewdidload Because I am loading another data on the same page, you can modify as per your choiceTrotta
O
0

I think you can use UIPageViewController. I did something like this for my project. This tutorial is helpful.

https://spin.atomicobject.com/2015/12/23/swift-uipageviewcontroller-tutorial/

Outsize answered 21/9, 2016 at 13:3 Comment(2)
I already have done that. Now I want something like a teaser on the first page to show the user that there are more pages to come and he can scroll through. Like a little edge in the right lower corner that curls a little.Pleasance
I hear you. The way I implemented this in my project I am using a UIButton with curl image background and when the user presses that button it will trigger the curl animation.Outsize

© 2022 - 2024 — McMap. All rights reserved.