子类UIAlertView中没有的iOS 4.2绘制正确 [英] Subclassed UIAlertView not drawn correctly in iOS 4.2

查看:134
本文介绍了子类UIAlertView中没有的iOS 4.2绘制正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一个子类UIAlertView中如下:

I've subclassed an UIAlertView as follow:

@interface NarrationAlertView : UIAlertView {
    UIImage * backgroundImage; //The image I want as custom background
    UILabel * textualNarrationView; //The test I wanna be displayed on the view        
}

和实现这种方式:

- (id)initNarrationViewWithImage:(UIImage *)image{

    if (self = [super init]){
        UILabel * alertTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.textualNarrationView = alertTextLabel;
        [alertTextLabel release];
        [self addSubview:alertTextLabel];
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    /* Here I draw the image as background */
    CGSize imageSize = self.backgroundImage.size;
    [self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
}

- (void)layoutSubviews {
    /* To fit the text */
    [textualNarrationView sizeToFit];

    CGRect textRect = textualNarrationView.frame;
    textRect.origin.x = (CGRectGetWidth(self.bounds) - CGRectGetWidth(textRect)) / 2;
    textRect.origin.y = (CGRectGetHeight(self.bounds) - CGRectGetHeight(textRect)) / 2;
    textRect.origin.y -= 70;
    textualNarrationView.frame = textRect;
}

- (void)show{
    /* Showing the view */
    [super show];
    CGSize imageSize = self.backgroundImage.size;
    self.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
}

在iOS上的previous版本(我一直在测试的仿真器)子类运行正常,并表示,当在其上显示正确绘制自定义背景图片和只是文字而在4.2版本,它绘制UIAlertView中经典的​​背景(蓝色圆角矩形)的我的图像的顶部

On the previous versions of iOS (I'm always testing on the simulator) the subclass run fine and when shown it displayed the custom background image drawn correctly and just text upon it, whereas in the 4.2 version it draws the UIAlertView classic background (the blue rounded corners rectangle) on top of my image.

我是什么做错了吗?有关UIAlertView中编程和UIView的任何建议也将是AP preciated。

What am I doing wrong? Any suggestion about UIAlertView programming and UIView too will be appreciated.

更新有没有人得到了一些UIAlertView中替换类分享?

UPDATE Has anyone got some UIAlertView replacement class to share?

推荐答案

我们曾与UIAlertView中在iOS 4.2的一个类似的问题;我们自定义布局,添加文本框和重新排列的按钮。

We had a similar problem with UIAlertView in iOS 4.2; we were customizing the layout, added text boxes and rearranging the buttons.

这不会是一个普遍的回答,但由于改变UIAlertView中,我们已经完全使用它为此放弃。我们都知道这是因为定制脆弱的执行/子类UIAlertView中不正式支持,使有关视图层次的内部结构假设,但4.2的发布确实踢我们进档。

This won't be a popular answer, but due to the changes to UIAlertView, we had to abandon using it entirely for this purpose. We always knew it was a fragile implementation since customizing/subclassing UIAlertView isn't officially supported and makes assumptions about the internal structure of the view hierarchy, but the release of 4.2 really kicked us into gear.

在年底,我们实现了我们自己的UI元素,以取代自定义UIAlertView中。

In the end, we implemented our own UI element to replace the customized UIAlertView.

这篇关于子类UIAlertView中没有的iOS 4.2绘制正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆