ios - 模态视图透明背景 - 停止下层隐藏?

标签 ios objective-c modalviewcontroller

我有一个共享页面的简介,其中涉及单击共享按钮和出现在顶部的具有一些共享功能的模态视图。

我的问题是我希望模态视图的背景是半透明的,因此显示下面的 View 。我已经设置了模态层的背景属性,当模态出现时,下面的层会短暂可见 - 看起来完全符合我的要求 - 但一旦封面过渡完成,背景 View 就会隐藏 - 有什么办法吗这个?

(顺便用IOS7)

干杯

更新 - @Tommaso Resti 好心地帮助我尝试解决这个问题 - 解释我到目前为止所做的事情 - 我的主 Storyboard 包含一个未链接的 uiview,标识符为“ShareScreenView” -单击按钮时,我想将其作为透明模式添加到我的 mainView 中。我已将按钮链接为 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 ])];

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

enter image description here

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

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

现在没有错误了——但是没有任何反应也没有错误..

最佳答案

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

像这样:

/* 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");
    }
}];

比用这个动画移除:

/* 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”。 我从不尝试我的代码...我的错 ;)

示例已更新!

关于ios - 模态视图透明背景 - 停止下层隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19998359/

相关文章:

ios - 如何以编程方式将现有 GCP 存储桶集成/访问到 Firebase Swift 应用程序?

ios - [__NSArrayM intValue] : unrecognized selector sent to instance

ios - iOS 建议的 GRG 非线性约束求解器

ios - 为什么我的 ModalView 以纵向模式显示?

ios - 如何用SWIFT编程语言实现SOAP Web服务?

ios - 监控 ibeacon 时替代 didexitregion

ios - 如何使用 UIGestureRecognizer 识别字母

ios - WatchKit 扩展 : Page-based hierarchy for glances

ios - 关闭 Modal Segue 后更新 UIViewController

ios - NavigationController 中的 ModalViewCOntroller