简体   繁体   English

自定义过渡将UIViewController扩展到左侧

[英]Custom Transition Expanding UIViewController to the left

I am trying to create a custom animation to present a new view controller into display. 我正在尝试创建一个自定义动画,以将新的视图控制器显示出来。 The from view controller is a view controller that has two embed uiviewcontrollers from视图控制器是具有两个嵌入式uiviewcontrollers的视图控制器 在此处输入图片说明 The one on the right is a view controller enclosed in a navigation controller and the first half of the animation that I am attempting is to make the right container expand to the left going full screen. 右边的一个是封装在导航控制器中的视图控制器,而我尝试制作的动画的前半部分是使右边的容器扩展到左边的全屏显示。

When I perform the standard UIView animation block setting its frame = its parent frame it first sets the size immediately (ignoring the animation) by expanding to the right, and then centers itself. 当我执行标准的UIView动画块设置其框架=其父框架时,它首先通过向右扩展立即设置大小(忽略动画),然后将其居中。

Basically my question is does anyone have a suggestion on how to force the view controller to expand strictly to the left direction at the proper speed ? 基本上我的问题是有人对如何强制视图控制器以适当的速度严格向左扩展提出建议吗? Scale doesn't work to my knowledge as it stretches the view not preserving aspect ratio. 就我所知,缩放不起作用,因为它会扩展视图而不保留宽高比。

This can be done by animating the size or position of the container views. 这可以通过设置容器视图的大小或位置的动画来完成。 In a test, I set up the container views such that the left one had a width constraint (IBOutlet, widthCon), and the right container had a 0 length spacing constraint to the left container. 在一个测试中,我设置了容器视图,以使左边的容器具有宽度约束(IBOutlet,widthCon),而右边的容器对左边的容器的长度间隔约束为0。 Expanding was done with this code in the parent view controller, 在父视图控制器中使用此代码进行了扩展,

- (void)expandRightView {

    [UIView animateWithDuration:2 animations:^{
        self.widthCon.constant = 0;
        [self.view layoutIfNeeded];
    }];
}

It can also be done by moving the left container to the left instead (leftCon is the IBOutlet to the constraint between the left container view and the left edge of the main view), 也可以通过将左侧容器移到左侧来完成操作(leftCon是IBOutlet到左侧容器视图和主视图左侧边缘之间的约束),

- (void)expandRightView {

    [UIView animateWithDuration:2 animations:^{
        self.leftCon.constant = -self.leftContainerView.frame.size.width;
        [self.view layoutIfNeeded];
    }];
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM