【问题标题】:view loading from the bottom doesn't fill whole view从底部加载视图不会填满整个视图
【发布时间】:2020-01-07 22:09:02
【问题描述】:

当我在 Xcode 中触摸按钮时,我正在使用此代码加载视图。

UIStoryboard *storyboard = self.storyboard;
UIViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"FirstCar"];[self presentViewController:svc animated:YES completion:nil];

视图从底部加载,我希望它没有,而是从侧面加载。主要问题是当它完成加载时,顶部有大约 1/2 英寸的间隙。我已使用此代码将其加载到顶部上方,具体取决于屏幕尺寸。

backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(-20, -20, 454, 776)];

以前可以正常工作,但现在由于某种原因不能正常工作。当我使用“DragView”顶/按住一个对象以移动它时,该对象会突然移动,但整个视图会上下移动。我什至可以通过向下滑动使视图内容完全消失。它不会去以前的视图只是完全空白的黑色。我不知道这是否相关,但有些奇怪。 有谁知道我做错了什么。 提前致谢。

【问题讨论】:

    标签: ios xcode presentviewcontroller


    【解决方案1】:

    您所描述的是 iOS 13 中呈现的视图控制器的默认行为 - 呈现的 VC 从底部滑入并在顶部留出空隙(表示用户可以通过向下拖动来关闭)。

    您可以通过将显示的 VC 的 modalPresentationStyle 设置为全屏来消除间隙(和向下滑动行为),如下所示:

    svc.modalPresentationStyle = UIModalPresentationFullScreen;
    

    在调用 present 之前添加该行(或者您可以在情节提要中设置该值),您应该会看到它覆盖了屏幕。您可以找到其他演示样式的文档in the Apple docs

    至于您提到的从右到左的动画,横向滑入通常与 UINavigation 控制器推送而不是模态演示相关联,但正如 this post 中提到的,您可以使用自定义过渡。

    这是该帖子中的相关代码:

    CATransition *transition = [[CATransition alloc] init];
    transition.duration = 0.5;
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromRight;
    [transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [self.view.window.layer addAnimation:transition forKey:kCATransition];
    [self presentViewController:svc animated:false completion:nil];
    

    【讨论】:

    • 谢谢谢谢谢谢。它解决了问题,即使滑动关闭也可以再次工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 2021-07-17
    • 2020-12-12
    • 2016-02-20
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多