【问题标题】:UITextView inside UIAlertView subclassUIAlertView 子类中的 UITextView
【发布时间】:2010-08-14 10:44:05
【问题描述】:

我正在尝试将 UITextView 放在我使用我的背景图像创建的 UIAlertView 的自定义子类中。 UITextView 仅用于显示大量文本(因此滚动)。 这是我的子类的代码

- (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 也是,但在几分之一秒后它全部跳起来(似乎是坐标问题)。

【问题讨论】:

  • 如果我没记错的话,如果屏幕上有太多文字,UIAlert 会自动添加一个 UITextView...
  • 那么在初始化时我应该在哪里添加我的文本?
  • 目前我使用 UILabel 采取了另一个方向。如果我能找到它,我会发布一个解决方案

标签: iphone uiview uitextview uialertview


【解决方案1】:

我终于创建了自己的 UIAlertView 自定义版本,并在其中提供了 UITextViewHere 是我这样做的原因。

通过这样做,当我尝试将 UITextView 附加到背景 UIImageView 作为子视图时,我遇到了一种奇怪的行为,它不再响应触摸,使其按预期工作的方法是将其附加到基础视图并实现以下方法

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

在必要时让它返回YES

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    相关资源
    最近更新 更多