2010-08-14 58 views
0

我试图把一个UITextView放在UIAlertView的自定义子类中,我使用我的背景图像创建。 UITextView仅用于显示大量的文本(所以滚动)。 这里是我的子类的代码UIAlertView里面的UIAlertView子类

- (id)initNarrationViewWithImage:(UIImage *)image text:(NSString *)text{ 
    if (self = [super init]) { 
     self.backgroundImage = image; 
     UITextView * textView = [[UITextView alloc] initWithFrame:CGRectZero]; 
     self.textualNarrationView = textView; 
     [textView release]; 
     self.textualNarrationView.text = text; 
     self.textualNarrationView.backgroundColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0]; 
     self.textualNarrationView.opaque = YES; 
     [self addSubview:textualNarrationView]; 
    } 
    return self; 
} 

- (void)drawRect:(CGRect)rect { 

    NSLog(@"DRAU"); 
    CGSize imageSize = self.backgroundImage.size; 
    [self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)]; 
} 

- (void)layoutSubviews { 


    CGSize imageSize = self.backgroundImage.size; 
    self.textualNarrationView.bounds = CGRectMake(0, 0, imageSize.width - 20, imageSize.height - 20); 
    self.textualNarrationView.center = CGPointMake(320/2, 480/2); 


} 

- (void)show{ 
    [super show]; 
    NSLog(@"SCIO"); 
    CGSize imageSize = self.backgroundImage.size; 
    self.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height); 
    self.center = CGPointMake(320/2, 480/2); 
} 

这是我第一次继承一个UIView,我肯定失去了一些东西,因为背景出现正确的图像,该UITextView的也不过一秒钟的一小部分后,所有跳跃(似乎是一个协调问题)。

+1

如果我没有弄错,UIAlert会自动添加一个UITextView,如果屏幕上显示的文字过多... – dododedodonl 2010-08-14 10:54:51

+0

那么我应该在什么地方添加我的文本? – rano 2010-08-14 10:58:10

+0

目前我用UILabel代替另一个方向。如果我找到它,我会发布一个解决方案 – rano 2010-08-17 06:27:39

回答

0

我终于创建了我自己的定制版本UIAlertView,并在其中提供了UITextViewHere是什么让我这样做。

通过这样做,当我试图将UITextView作为子视图附加到背景UIImageView时,我经历了一个奇怪的行为,它无法响应触摸了,让它按预期工作的方法是将它附加到基本视图和通过使其返回YES当encessary实现以下方法

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer