以编程方式在iOS中将另一个UIViewController显示为弹出窗口?
我有主仪表板(以编程方式在iOS中将另一个UIViewController显示为弹出窗口?,ios,objective-c,uiviewcontroller,popup,Ios,Objective C,Uiviewcontroller,Popup,我有主仪表板(UITableViewController),登录后,我需要显示此页面,并显示一条欢迎消息,该消息正在使用UIViewController显示 如何从我的viewdidappease()方法中显示此弹出窗口 我正在使用下面的代码,但它不起作用 -(void)viewDidAppear:(BOOL)animated{ popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup
UITableViewController
),登录后,我需要显示此页面,并显示一条欢迎消息,该消息正在使用UIViewController
显示
如何从我的viewdidappease()
方法中显示此弹出窗口
我正在使用下面的代码,但它不起作用
-(void)viewDidAppear:(BOOL)animated{
popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup"];
[popupObj setModalPresentationStyle:UIModalPresentationCurrentContext];
}
请帮帮我
我看到了几个链接
更新
当我把代码改成这个的时候
-(void)viewDidAppear:(BOOL)animated{
popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup"];
// [popupObj setModalPresentationStyle:UIModalPresentationCurrentContext];
popupObj.modalPresentationStyle = UIModalPresentationOverCurrentContext;
popupObj.modalTransitionStyle = UIModalPresentationPopover;
[self presentViewController:popupObj animated:YES completion:nil];
}
现在我可以看到我的UIViewController
作为弹出窗口出现,但现在UIViewController
全屏显示
但是我只需要这个
框架(320320)
您的代码创建视图控制器并设置其显示样式,但实际上并不显示它。为了实现这一点,您需要在您现在拥有的两行之后添加以下内容:
[self presentViewController:popupObj animated:true completion:nil];
您可以将UIViewController添加为子视图,并设置其框架,使其看起来像弹出窗口。
希望这将对您有所帮助。请在您的rootviewcontroller上设置导航控制器:
-(void)viewDidAppear:(BOOL)animated
{
popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup"];
[self.navigationController presentViewController:popupObj animated:YES completion:nil];
}
或
我有两条路,也许不太好,但大部分时间都在工作 首先,当第二个视图控制器出现时,显示第一个视图控制器的屏幕截图。像这样:
- (void)setBackGround {
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, [UIScreen mainScreen].scale);
[self.presentingViewController.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.layer.contents = (__bridge id)(image.CGImage);
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (!_isShown) {
_isShown = YES;
[self setBackGround];
}
}
在初始化时不要忘记设置“\u isShown=NO”
第二:您只能初始化一个视图,并在带有动画的视图控制器上显示它。代码位于:
我在博客上更新了一个例子。
链接问题的答案提供了大量代码,您是否尝试全部实现,或者这两行是您唯一尝试的内容?是的,尝试了与此相关的所有内容您可以编辑问题以包含所有相关代码吗?还包括您期望它做什么和实际做了什么的描述。显示viewcontroller的代码在哪里?现在更新问题它应该可以工作了,帧中的更改是否只影响x、y,甚至不影响它的宽度和高度?
-(void)viewDidAppear:(BOOL)animated
{
popupObj= [self.storyboard instantiateViewControllerWithIdentifier:@"popup"];
[self.view addSubview:popupObj.view];
}
- (void)setBackGround {
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, [UIScreen mainScreen].scale);
[self.presentingViewController.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.layer.contents = (__bridge id)(image.CGImage);
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (!_isShown) {
_isShown = YES;
[self setBackGround];
}
}