how to add close button to modal view corner which is presented in UIModalPresentationPageSheet?

自作多情 提交于 2019-11-30 21:55:15

You can try and add it to the the topmost application window:

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

This should give you the right view to allow the button to appear on top of the modal and receive touch events.

--edit--

To position the button you can try something like this:

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];
}];

This will get the frame of the modalView that has been presented. You can then set your button's origin to be offset and set the adjusted frame.

See if this works:

myPresentedView.clipsToBounds = NO;

That will allow the button to draw itself beyond it's views. One drawback to this is that the touches will not land beyond the views bounds, so try not to set the button too far away.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!