首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用presentModalViewController创建透明视图

如何使用presentModalViewController创建透明视图
EN

Stack Overflow用户
提问于 2009-02-25 20:20:42
回答 18查看 92K关注 0票数 80

我正在使用以下内容显示模式视图

代码语言:javascript
复制
[self presentModalViewController:controller animated:YES];

当视图在屏幕上移动时,根据创建它的xib文件中的设置,它是透明的,但一旦它填满屏幕,它就会变得不透明。

有没有保持视图透明的方法?

我怀疑它放在上面的视图没有被渲染,而不是模式视图变得不透明。

EN

回答 18

Stack Overflow用户

回答已采纳

发布于 2009-02-25 21:22:55

您的视图仍然是透明的,但是一旦您的模态控制器位于堆栈的顶部,它后面的视图就会被隐藏(就像任何最顶层的视图控制器一样)。解决方案是自己手动设置视图动画;然后,后台的viewController将不会被隐藏(因为您不会“离开”它)。

票数 63
EN

Stack Overflow用户

发布于 2013-01-20 00:19:34

我需要做的是让它工作:

代码语言:javascript
复制
self.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
票数 48
EN

Stack Overflow用户

发布于 2009-08-30 15:55:15

对于那些想看一些代码的人,下面是我在透明视图的控制器中添加的内容:

代码语言:javascript
复制
// Add this view to superview, and slide it in from the bottom
- (void)presentWithSuperview:(UIView *)superview {
    // Set initial location at bottom of superview
    CGRect frame = self.view.frame;
    frame.origin = CGPointMake(0.0, superview.bounds.size.height);
    self.view.frame = frame;
    [superview addSubview:self.view];            

    // Animate to new location
    [UIView beginAnimations:@"presentWithSuperview" context:nil];
    frame.origin = CGPointZero;
    self.view.frame = frame;
    [UIView commitAnimations];
}

// Method called when removeFromSuperviewWithAnimation's animation completes
- (void)animationDidStop:(NSString *)animationID
                finished:(NSNumber *)finished
                 context:(void *)context {
    if ([animationID isEqualToString:@"removeFromSuperviewWithAnimation"]) {
        [self.view removeFromSuperview];
    }
}

// Slide this view to bottom of superview, then remove from superview
- (void)removeFromSuperviewWithAnimation {
    [UIView beginAnimations:@"removeFromSuperviewWithAnimation" context:nil];

    // Set delegate and selector to remove from superview when animation completes
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

    // Move this view to bottom of superview
    CGRect frame = self.view.frame;
    frame.origin = CGPointMake(0.0, self.view.superview.bounds.size.height);
    self.view.frame = frame;

    [UIView commitAnimations];    
}
票数 24
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/587681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档