如何在IOS上将自定义视图放在另一个视图上 [英] How to Place custom view in IOS over another view

查看:1003
本文介绍了如何在IOS上将自定义视图放在另一个视图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 UIViewController 上实现以下自定义视图。什么是实现它的最佳方式,而不是使用addSubview我想更好地使用一些东西。

我以前使用过以下但我想现在更好地使用一些东西

I want to achieve following custom view over UIViewController . What is the best way to acheive it rather then using addSubview I want to use some thing better.
I previously use following but i want to use some thing better now

[self.view addSubview:NotConnected.view];

 [self.view removeFromSuperview];

我使用 https://github.com/wimagguc/ios-custom-alertview

我不喜欢使用库,所以如何在另一个<$ c $上自定义 UIViewController c> UIViewController ,如上图所示。我使用

I didn't prefer to use library so how is it possible to customise UIViewController over another UIViewController as shown in image above. I use

- (IBAction)ContinueToPayment:(id)sender {

    PayByVC *Newpage = [[PayByVC alloc] initWithNibName:@"PayByVC" bundle:nil];
    Newpage.checkOutInfoDict=checkOutDict;
    Newpage.modalPresentationStyle   = UIModalPresentationOverCurrentContext;
    Newpage.modalTransitionStyle     = UIModalTransitionStyleCrossDissolve;
    Newpage.view.backgroundColor     = [[UIColor blackColor] colorWithAlphaComponent:.4];
    Newpage.delegate = self;
    [self presentViewController:Newpage animated:YES completion:nil];


}

要从超级视图中删除我使用过

To remove from super view I have used

 [self dismissViewControllerAnimated:YES completion:nil];

如何在所有类型的屏幕方向上将payby视图放在屏幕中央

How can I place the payby view in centre of screen in all type of screen orientation

推荐答案

使用带有 OverFullScreen 模式的模态演示。将ViewController视图的背景设置为透明,并将自定义视图放在其中心。

Use a Modal presentation with OverFullScreen mode. Set the background of the ViewController's view to transparent and place your custom view in the center of it.

最简单的方法是使用故事板。在中心创建一个包含自定义视图的视图控制器。否则,您需要调用 view.addSubView(..)将自定义视图放在中心并相应地创建约束。
要显示此视图控制器,您可以创建一个segue或通过代码 presentViewController(...)。不要忘记将 modalPresentationStyle 设置为 OverFullScreen

Easiest would be to use storyboards. Create a view controller with your custom view in the center. Otherwise, you need to call view.addSubView(..) to place your custom view on the center and create the constraints accordingly. To present this view controller you can create a segue or by code presentViewController(...). Don't forget to set the modalPresentationStyle to OverFullScreen.

不需要库。

这篇关于如何在IOS上将自定义视图放在另一个视图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆