2010-08-14 61 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