[ios]UITextView 子视图 UIImageView 隐藏输入文本和与文本 iPhone 滚动?

发布时间: 2015/3/29 15:27:18
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我有 UITextView 在我的 iPhone 应用程序。在 UITextView i have added UIImageView as subview 。当输入的文本达到 final height the texts are scrolling to top 。而 UIImageView (with image) also scrolling top 。怎么能处理停止图像滚动,并允许滚动文本?这里是我的准则,供你方参考

    messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
    messageTextView.delegate = self;
    messageTextView.backgroundColor = [UIColor clearColor];
    messageTextView.clipsToBounds = YES;  
    messageTextView.font = [UIFont fontWithName:@"Helvetica" size:14];
    messageTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

    textViewImageView = [[UIImageView alloc]initWithFrame: CGRectMake(0, 0, 210, 30)];
    textViewImageView.image = [UIImage imageNamed: @"textbg.png"];
    textViewImageView.contentMode    = UIViewContentModeScaleToFill;
    textViewImageView.contentStretch = CGRectMake(0.5, 0.5, 0, 0);  
    [messageTextView addSubview: textViewImageView];

    [messageTextView sendSubviewToBack: textViewImageView];
    [messageTextView addSubview:textViewLabel];

任何人都可以请帮我解决这个问题吗?感谢在前进。期待着您的回复。

enter image description here

解决方法 1:

你有否考虑位置后面的 textView imageView 吗?或是否有任何禁止这种布局的理由?

就像这样:

UITextView *messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
// ...
messageTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:messageTextView];

UIImageView *textViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(35, 5, 210, 30)];
// ...
textViewImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:textViewImageView];

[self.view sendSubviewToBack:textViewImageView];
官方微信
官方QQ群
31647020