从底部加载的视图无法填充整个视图

问题描述 投票:0回答:1

当我触摸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个回答
0
投票

您所描述的是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];
© www.soinside.com 2019 - 2024. All rights reserved.