简体   繁体   English

如何在两个子视图 iOS 之间创建过渡?

[英]How can I create a transition between two subview iOS?

I have a problem when I want to create a transition between to views inside a container view in iOS application.当我想在 iOS 应用程序中的容器视图内创建视图之间的转换时,我遇到了问题。 I want to create an animation that makes my first view goes out sliding to the left and the second coming from the right (like switching between photos, a sort of push in Navigation Controller).我想创建一个 animation 使我的第一个视图向左滑动,第二个从右侧滑动(例如在照片之间切换,导航控制器中的一种推送)。 I created my animation but the problem is that my subview does not disappear once reached the border of my container view but when it reaches the edge of my screen.我创建了我的 animation 但问题是我的子视图在到达我的容器视图的边界时并没有消失,但是当它到达我的屏幕边缘时。

I used this code:我使用了这段代码:

CATransition *transition = [CATransition animation];
transition.duration = animationTime;
transition.type = kCATransitionPush;
transition.subtype = transationSubtype;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
transition.removedOnCompletion = YES;
[view.layer addAnimation:transition forKey:nil];

在此处输入图像描述

As visible in the image the red square goes out from the screen and not from its container and also the green comes inside from the screen edge and not from the container view edge.如图所示,红色方块从屏幕而不是从其容器中消失,绿色从屏幕边缘进入内部,而不是从容器视图边缘进入。 I want instead that the animation ends when reaches the container view edge.我希望 animation 在到达容器视图边缘时结束。

I tried anything but I was not able to find something useful.我尝试了任何东西,但找不到有用的东西。

Try to set clipsToBounds property of the container view to YES尝试将容器视图的 clipsToBounds 属性设置为 YES

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (iOS)如何在两个ViewController之间的过渡中为UI元素(例如标签和图像)的过渡设置动画? - (iOS) How can i animate the traslation of UI elements, like labels and images in the transition between two viewcontrollers? 如何为两个模态视图控制器之间的过渡设置动画? - How can I animate the transition between two modal view controllers? iOS子视图自定义转换 - iOS subview custom transition 如何使用 iOS swift hero 框架在两个视图控制器之间进行转换? - How to use iOS swift hero framework for transition between two viewcontrollers? 如何在iOS设备上滑动手势时“捕获”子视图? - How can I “catch” a subview during a swipe gesture on an iOS device? iOS Swift如何在SubView顶部添加元素 - IOS Swift How can I add element on top of a SubView 如何在 iOS 的状态栏和导航栏顶部添加子视图? - How can I add a subview under statusbar and on top of Navigationbar in iOS? 如何挂钩子视图的子视图? - How can I hook a subview of a subview? 如何在Xamarin iOS中的一个子视图下设置一个子视图 - How can I set one subview below another subview in xamarin iOS 如何使用“滚动”过渡样式要求两根手指在UIPageViewController的页面之间滚动? - How can I require two fingers to scroll between pages of a UIPageViewController using the ‘scroll’ transition style?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM