ios - 使用动画从右到左移除 View

标签 ios iphone uiview uiviewanimation

顺便说一句,当我从左到右单击时添加 View ,并想从右到左删除该 View 。

下面是我从左到右添加 View 时的代码

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                         bundle: nil];

leftMenu = (LeftMenuViewController*)[mainStoryboard
                                                             instantiateViewControllerWithIdentifier: @"menuController"];



leftMenu.view.frame = CGRectMake(-320, 0, 320-50, self.view.frame.size.height);


[self addChildViewController:leftMenu];
[self.view addSubview:leftMenu.view];

[UIView animateWithDuration:0.3 animations:^{

    leftMenu.view.frame = CGRectMake(0, 0, 320-50, self.view.frame.size.height);
    hoverView.hidden = NO;


} completion:^(BOOL finished) {
    [leftMenu didMoveToParentViewController:self];
}];

为了从右到左移除这个 View ,我尝试过的是:

 self.view.frame = CGRectMake(320-50, 0, self.view.frame.size.width, self.view.frame.size.height);
[self willMoveToParentViewController:nil];


[UIView animateWithDuration:0.3 animations:^{

    self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);



} completion:^(BOOL finished) {

    [self removeFromParentViewController];
    [self.view removeFromSuperview];

}];

我想从右到左移除 View 。对如何进一步进行有帮助吗?

最佳答案

您必须将您的 subview 移出父 View 的框架,因此将您的 subview 的 x 坐标设置为其自身宽度的负值。这将导致您的 View 从右向左移出 View 。

[self willMoveToParentViewController:nil];

    [UIView animateWithDuration:0.3 animations:^{

        self.view.frame = CGRectMake(-self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {

        [self removeFromParentViewController];
        [self.view removeFromSuperview];

    }];

关于ios - 使用动画从右到左移除 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31153633/

相关文章:

c# - 加密 mdm 配置文件

iphone - 基于页面的应用加载 epub

iphone - 如何让ui始终响应并进行后台更新?

ios - 在 initWithCoder : 上查看 1000x1000

ios - 找不到属性 'navigationController'。 UIView界面

ios - 其他 View 之上的 UIView 不起作用

iphone - ARC 语义问题 : No visible @interface for Class declares the selector

ios - Firebase iOS 在后台和前台推送通知

ios - 仅在一个 ViewController 中更改导航栏属性

ios - 第二次加载 UIView 后 NSConstraints 使应用程序崩溃