ios uiview uiimageview uitextview

发布于 2024-12-20 14:54:24 字数 876 浏览 1 评论 0原文

我有一个主 UIView,上面有一个 UIImageView,并且 UIView 添加了一个 UITextView 作为子视图。 UITextView的框架比UIView小。 UIImageView 实际上是一个框架,图像的其余部分是透明的并且适合 UIView 的完整大小,但 UITextView 始终位于 UIView 之上。我想要实现的是 UITextView 在前台显示 UIView,同时可以在 UITextView 上上下滚动。

使其成为可能的正确方法是什么?


我当前的代码不起作用:

in loadView:

self.contentview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.contentview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ChristmasFrame.png"]]; 
self.contentview.opaque = NO;
self.contentview.userInteractionEnabled = YES;
[self setView:self.contentview];

in viewDidLoad:

[self.contentview addSubview:self.textview];
[self.contentview sendSubviewToBack: self.textview];

我希望 UITextView 位于 self.contentview 后面,这样它就可以在 UITextView 上显示其背景图像。

I have a main UIView that has an UIImageView on it, and the UIView adds an UITextView as a subview. UITextView's frame is smaller than UIView. UIImageView is actually a frame and the rest of the image is transparent and fits the full size of the UIView, but the UITextView is always upon UIView. What I want to achieve is UITextView shows UIView in foreground, while it is possible to scroll up and down on UITextView.

What is the proper way to make it possible?


My current code that does not work:

in loadView:

self.contentview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.contentview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ChristmasFrame.png"]]; 
self.contentview.opaque = NO;
self.contentview.userInteractionEnabled = YES;
[self setView:self.contentview];

in viewDidLoad:

[self.contentview addSubview:self.textview];
[self.contentview sendSubviewToBack: self.textview];

I want UITextView to be behind self.contentview, so it could show its background image upon the UITextView.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羁客 2024-12-27 14:54:25

尝试在 UITextView 之上的 UIView 上将 setUserInteractionEnabled: 设置为 NO

如果这不起作用,您可以尝试覆盖hitTest:withEvent:

try setting setUserInteractionEnabled: to NO on UIView what is on top of UITextView

if that not working you could try to override hitTest:withEvent:

你对谁都笑 2024-12-27 14:54:25

将清晰的颜色设置为textview的背景色。
并在 UIView 上方添加文本视图

make clear color as textview's background color.
and add text view above UIView

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文