gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:37 24 4
gpt4 key购买 nike

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

我的问题是我希望模态视图的背景是半透明的,因此显示下面的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com