ios – 如何通过拖动手指在两个视图之间执行翻转动画?

ios – 如何通过拖动手指在两个视图之间执行翻转动画?,第1张

概述我想在用户从屏幕右侧拖动手指时执行翻转动画.动画的状态应受拖动长度的影响,不应自动工作. 我使用过这样的东西: if (transitionBegan) { flipTransition = CATransform3DIdentity; flipTransition.m34 = 1.0 / -500; flipTransition = CATransform3DRotat 我想在用户从屏幕右侧拖动手指时执行翻转动画.动画的状态应受拖动长度的影响,不应自动工作.

我使用过这样的东西:

if (TransitionBegan) {    flipTransition = CAtransform3DIDentity;    flipTransition.m34 = 1.0 / -500;    flipTransition = CAtransform3DRotate(flipTransition,degree * M_PI / 180.0f,0.0f,1.0f,0.0f);    self.vIEw.layer.transform = flipTransition;}

但现在我不知道如何实现我的视图之间的转换,以便视图A消失并且视图B出现.

你能帮助我吗?

解决方法 您可以编写一个手势识别器来为您进行变换.例如,假设您能够左右翻转,您可以执行以下 *** 作.但是我的想法是,如果你不到翻转的一半,你可以转换当前视图,如果超过一半,则转换下一个视图:

- (voID)handlePan:(UIPanGestureRecognizer *)gesture{    static UIVIEw *currentVIEw;    static UIVIEw *prevIoUsVIEw;    static UIVIEw *nextVIEw;    if (gesture.state == UIGestureRecognizerStateBegan)    {        // Set the three vIEw variables here,based upon the logic of your app.        // If there is no `prevIoUsVIEw` or `nextVIEw`,then set them to `nil`        // as appropriate.        // I happen to be choosing vIEws for child vIEw controllers for my         // custom container,but I'll spare you that in case you're not using        // custom container controller.    }    // lets set the "percent" rotated as the percent across the screen the user's    // finger has travelled    CGPoint translation = [gesture translationInVIEw:gesture.vIEw.supervIEw];    CGfloat percent = translation.x / gesture.vIEw.frame.size.wIDth;    CGfloat rotationPercent = percent;    // let's use the var to keep track of which vIEw will be rotated    UIVIEw *vIEwTotransform = nil;     if (percent < -0.5 && nextVIEw)    {        // if user has moved finger more than half way across the screen to        // the left,and there is a `nextVIEw`,then we're showing the second        // half of flip to the next screen        currentVIEw.hIDden = YES;        nextVIEw.hIDden = NO;        prevIoUsVIEw.hIDden = YES;        rotationPercent += 1.0;        vIEwTotransform = nextVIEw;    }    else if (percent > 0.5 && prevIoUsVIEw)    {        // if user has moved finger more than half way across the screen to        // the right,and there is a `prevIoUsVIEw`,then we're showing the second        // half of flip to the prevIoUs screen        currentVIEw.hIDden = YES;        nextVIEw.hIDden = YES;        prevIoUsVIEw.hIDden = NO;        rotationPercent -= 1.0;        vIEwTotransform = prevIoUsVIEw;    }    else if ((percent < 0 && nextVIEw) || (percent > 0 && prevIoUsVIEw))    {        // otherwise we're in the first half of the flip animation,so we're        // showing the `currentVIEw`        currentVIEw.hIDden = NO;        nextVIEw.hIDden = YES;        prevIoUsVIEw.hIDden = YES;        vIEwTotransform = currentVIEw;    }    // do the flip `transform`    CAtransform3D transform = CAtransform3DIDentity;    transform.m34 = 1.0 / -800;    vIEwTotransform.layer.transform = CAtransform3DRotate(transform,M_PI * rotationPercent,0.0,1.0,0.0);    // if we're all done,let's animate the completion (or if we dIDn't move far enough,// the reversal) of the pan gesture    if (gesture.state == UIGestureRecognizerStateEnded ||        gesture.state == UIGestureRecognizerStateCancelled ||        gesture.state == UIGestureRecognizerStateFailed)    {        // I'm personally using an index of my custom container child vIEws,so I'm        // just updating my index appropriately; your logic may obvIoUsly differ        // here.        if (percent < -0.5 && nextVIEw)            self.currentChildindex++;        else if (percent > 0.5 && prevIoUsVIEw)            self.currentChildindex--;        // and animate the completion of the flip animation        [UIVIEw animateWithDuration:0.25                              delay:0.0                            options:UIVIEwAnimationoptionCurveEaseInOut                         animations:^{                             prevIoUsVIEw.transform = CGAffinetransformIDentity;                             currentVIEw.transform = CGAffinetransformIDentity;                             nextVIEw.transform = CGAffinetransformIDentity;                         }                         completion:NulL];    }}
总结

以上是内存溢出为你收集整理的ios – 如何通过拖动手指在两个视图之间执行翻转动画?全部内容,希望文章能够帮你解决ios – 如何通过拖动手指在两个视图之间执行翻转动画?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1054037.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存