简体   繁体   English

在视图上方显示新的半透明VC

[英]Present new semi-transparent VC on top of view

I've looked around and i can't seem to figure out this. 我环顾四周,似乎无法弄清楚。

I'm simply trying to show a view on top of another one, but from another VC , and in storyboard . 我只是想在另一个视图之上显示一个视图,但是从另一个VCStoryboard中显示一个视图。

The "idea" behinf this view is a kind of a pop-up/alert, and it'll eventually need a collection view and multiple buttons. 该视图后面的“想法”是一种弹出窗口/警报,最终将需要一个集合视图和多个按钮。 So i figured i'd just do that with another VC since i need that "popup" in many places in the app. 因此,我认为我只需要使用另一个VC即可,因为我需要在应用程序的许多位置使用“弹出窗口”。

Right now, i can do it, but my view is not transparent (even though my alpha is set correctly), so I'm guessing that the "under" view is actually gone and i've just made a regular "segue" using a different method. 现在,我可以做到,但是我的视图不是透明的(即使我的Alpha设置正确),所以我猜测“ under”视图实际上已经消失了,我只是使用了常规的“ segue”一种不同的方法。 So i'm stuck. 所以我被困住了。

And I cant just copy paste the whole VC class everywhere i need it so i can "addsubview" it... 而且我不能只在需要的地方复制粘贴整个VC类,这样我就可以“ addsubview”它了。

Any idea? 任何想法?

This is what i'm doing : 这就是我在做什么:

AddFeelingViewController *adf = (AddFeelingViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"AddFeelingViewController"];

adf.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:adf animated:YES completion:nil];

The view appears and i can interact, but since it's very small i just need a "transparent background" which i haven't. 该视图出现,并且我可以进行交互,但是由于它很小,我只需要一个我没有的“透明背景”。 Also, i'm planning to have a fullscreen button that removes the view. 另外,我计划有一个全屏按钮删除视图。 The classic "hit somewhere to cancel" type of button. 经典的“在某处单击以取消”按钮。

Any help is much appreciated ! 任何帮助深表感谢 !

You should check this project on Github, it has exactly what you need in "custom transition". 您应该在Github上检查该项目,它确实具有“自定义过渡”中所需的内容。

https://github.com/schneiderandre/popping https://github.com/schneiderandre/popping

It was created using the Facebook pop animation engine. 它是使用Facebook流行动画引擎创建的。

Here is a way to get alpha value but you could instead of presenting the viewController, you could simply add it to current view as subview along with alpha value as shown below :- 这是一种获取Alpha值的方法,但是您可以代替呈现viewController,而只需将其与Alpha值一起作为子视图添加到当前视图中,如下所示:

-(IBAction)newView:(id)sender {
  demoVc = (YOUR_VIEW_CONTROLLER *)[self.storyboard instantiateViewControllerWithIdentifier:@"identifier"];

  demoVc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  [demoVc.view setAlpha:0.3];   //Set alpha value

   //    [self presentViewController:demoVc animated:YES completion:nil];

  [self.view addSubview:demoVc.view];
}

Also to remove you could simple create a IBAction method to remove it from superview. 同样,要删除它,您可以简单地创建一个IBAction方法以将其从超级视图中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM