如何添加关闭按钮,莫代尔这是在UIModalPresentationPageSheet呈现视图的角落

2019-08-22 14:51发布

我想在一个角落添加一个浮动关闭(X)按钮UIModalPresentationPageSheet查看。 效果如下图所示:

但是,将它添加到父视图可以显示在页面表的后面(也不可能挖掘),并将其添加到页面表将它的一部分隐藏的,因为它是从观看区域。

有没有更好的解决办法?

任何建议表示赞赏。

Answer 1:

你可以尝试,并把它添加到最顶层的应用程序窗口:

    add.modalPresentationStyle = UIModalPresentationPageSheet;
    [self presentViewController:add animated:YES completion:^{
        [[[[UIApplication sharedApplication] windows] lastObject] addSubview:button];
    }];

这应该给你正确的视图,允许按钮出现在模式的顶部和接收触摸事件。

- 编辑 -

要定位按钮,你可以尝试这样的事:

self.modalPresentationStyle = UIModalPresentationFormSheet;
add.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:pvc animated:YES completion:^{
    CGRect parentView = pvc.view.superview.frame;
    CGRect buttonFrame = button.frame;
    buttonFrame.origin = CGPointMake(parentView.origin.x - buttonFrame.size.width/2.0f, parentView.origin.y - buttonFrame.size.height/2.0f);

    [button setFrame:buttonFrame];
    [[[[UIApplication sharedApplication] windows] lastObject] addSubview:button];
}];

这将让已经提出的modalView的框架。 然后,您可以设置按钮的原点偏移,并设置调节的框架。



Answer 2:

看看这个工程:

myPresentedView.clipsToBounds = NO;

这将允许按钮绘制自身超越它的观点。 一个缺点,这是该触摸不会超出土地的意见界限,所以尽量不要设置按钮太远。



文章来源: how to add close button to modal view corner which is presented in UIModalPresentationPageSheet?