iOS 透明 View Controller

标签 ios modal-dialog transparent viewcontroller

我正在尝试创建一个透明的模式 ViewController,它覆盖当前的 ViewController。我将 backgroundcolor 设置为 clearcolor 但背景是黑色的, 因为另一个 View Controller 没有显示在新 View Controller 后面。我想要一个像 UIAlertView 这样的叠加层。

我谷歌了很多,我找到的唯一解决方案是添加一个 subview 。 我正在使用 iOS5。

最佳答案

将背景颜色设置为清除您呈现模型 View 后,将背景设置为清除然后再呈现将不起作用。

如果你想呈现像 UIAlertView 这样的 View ,使用这个-

CAKeyframeAnimation *animation = [CAKeyframeAnimation
        animationWithKeyPath:@"transform"];

    CATransform3D scale1 = CATransform3DMakeScale(0.5, 0.5, 1);
    CATransform3D scale2 = CATransform3DMakeScale(1.2, 1.2, 1);
    CATransform3D scale3 = CATransform3DMakeScale(0.9, 0.9, 1);
    CATransform3D scale4 = CATransform3DMakeScale(1.0, 1.0, 1);

    NSArray *frameValues = [NSArray arrayWithObjects:
        [NSValue valueWithCATransform3D:scale1],
        [NSValue valueWithCATransform3D:scale2],
        [NSValue valueWithCATransform3D:scale3],
        [NSValue valueWithCATransform3D:scale4],
        nil];
    [animation setValues:frameValues];//Courtesy zoul.fleuron.cz

    NSArray *frameTimes = [NSArray arrayWithObjects:
        [NSNumber numberWithFloat:0.0],
        [NSNumber numberWithFloat:0.5],
        [NSNumber numberWithFloat:0.9],
        [NSNumber numberWithFloat:1.0],
        nil];    
    [animation setKeyTimes:frameTimes];

    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.duration = .2;
    [self.backColor SETCOLOUR HERE];
    [self.layer addAnimation:animation forKey:@"uialertViewPopUP"];

您可以使用上面给出的代码覆盖 willMoveToSuperView 方法。

关于iOS 透明 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12562153/

相关文章:

ios - 在显示之前更改 UIActionsheet 按钮文本和背景

javascript - 将参数传递给模态

angular - 可拖动的 ngx-bootstrap 模态仅 body 移动和背景固定

c# - 透明或半透明面板控制

html - 使部分div边框透明html

css - 带有定位子元素的 IE alpha 透明度

ios - Openssl iOS 缓冲区限制

ios - Google 登录 CocoaPods 已弃用

ios - 打开Health通过URL Scheme去一个App的权限

angularjs - 防止在点击模式外部时关闭 Foundation 模式