![](/img/trans.png)
[英]UITextView Inside UIScrollView Scrolling Parent as Text is Entered
[英]UITextView subview UIImageView hiding entered text and scrolling with texts iPhone?
我的iPhone应用程序中有UITextView
。 在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];
有谁可以帮我解决这个问题? 提前致谢。 期待你的回复。
你考虑过将imageView放在textView后面吗? 或者是否有任何理由禁止这样的布局?
类似的东西:
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];
也许这可能有所帮助。 使用scrollview委托在图像到达边界时重新定位图像。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
CGRect imageFrame = textViewImageView.frame;
imageFrame.origin.y = scrollView.contentOffset.y - (scrollView.contentSize.height - scrollView.frame.size.height);
textViewImageView.frame = imageFrame;
}
}
这应该工作:
[yourTxtView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"your image.png"]]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.