模式查看透明背景 – 停止低层隐藏?

我有一个共享页面的简介,涉及点击共享button和模式视图出现在顶部与一些共享function。

我的问题是,我希望模态视图的背景是半透明的,因此显示下面的视图。 我已经设置了模态图层的背景属性,当模态出现时,下面的图层可以被简单地看到,并且看起来完全符合我的要求 – 但是一旦图层覆盖过渡完成,背景视图就会被隐藏 – 是否有任何方法这个?

(使用IOS7的方式)

干杯

更新 – @Tommaso Resti帮助我尝试解决这个问题 – 解释我到目前为止所做的事情 – 我的主要故事板包含一个未链接的uiview,标识符为“ShareScreenView” – 我想添加到我的mainView中点击一个button时,一个透明的模式。 我把这个button作为一个IBAction连接起来,并将下面的代码添加到我的方法中 –

- (IBAction)shareBtn:(id)sender { NSLog(@"clicked"); /* Create your view off the screen (bottom) */ /* NEW EDIT */ UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil]; UIViewController *myModalController = [mainStoryboard instantiateViewControllerWithIdentifier:@"ShareScreenView"]; [myModalController.view setFrame:CGRectMake(0, 568, 320, 568)]; // [myModalController.view setFrame: CGRectMake(0, [[UIScreen mainScreen].bounds.size.height], [[UIScreen mainScreen].bounds.size.width], [[UIScreen mainScreen].bounds.size.height])]; /* Animate it from the bottom */ [UIView animateWithDuration:.5 animations:^{ CGAffineTransform move = CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height); [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; myModalController.view.transform = move; /* UPDATED HERE */ NSLog(@"Atrying"); } completion:^(BOOL finished) { NSLog(@"Adid try"); if(finished) { NSLog(@"Animation completed"); } }]; } 

但是我得到一个错误 –

[myModalController.view setFrame:CGRectMake(0,[[UIScreen mainScreen] .bounds.size.height],[[UIScreen mainScreen] .bounds.size.width],[[UIScreen mainScreen] .bounds.size.height])] ;

它只是指出“预期的标识符”与箭头指向高度(见下面的屏幕截图)

在这里输入图像说明

所以我尝试添加属性如下 –

  [myModalController.view setFrame:CGRectMake(0, 568, 320, 568)]; 

现在没有错误 – 但没有发生,没有错误..

我build议使用你自己的方法:

像这样的东西:

 /* Create your view off the screen (bottom) */ /* NEW EDIT */ UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; UIViewController *myModalController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MyModalController"]; [myModalController.view setFrame: CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; [self.view addSubview: myModalController.view]; /* UPDATED HERE! */ /* Animate it from the bottom */ [UIView animateWithDuration:.5 animations:^{ CGAffineTransform move = CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height); [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; myModalController.view.transform = move; /* UPDATED HERE */ } completion:^(BOOL finished) { if(finished) { NSLog(@"Animation completed"); } }]; 

比用这个animation去除:

 /* Reset animation */ [UIView animateWithDuration:.5 animations:^{ CGAffineTransform reset = CGAffineTransformIdentity; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; myModalController.view.transform = reset; /* UPDATED HERE */ } completion:^(BOOL finished) { if(finished) { NSLog(@"Reset completed"); [myModalController.view removeFromSuperview]; } }]; 

—编辑—对不起,我忘了在myViewController后添加“.view”。 我从来没有尝试我的代码…我的错;)

该示例已更新!

您可以创build一个视图,从底部滑入,然后使视图半透明。

你可以使用View Container来创build你自己的ModalViewController,并像@Tommaso Resti所说的那样做animation