iOS - UIToolBar 作为 UITextView 的 inputAccessoryView
我添加了一个带有 UIBarButtonItem
的 UIToolBar
作为 UITextView
的 inputAccessoryView。它工作正常,但 UIBarButtonItem 在其框架之外是可触摸的,也许在右侧外侧 50 像素处。这没什么大不了的,但它让我很烦恼。有人知道为什么吗?
这是我的代码(ARC):
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
toolBar.barStyle = UIBarStyleBlack;
toolBar.translucent = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneWriting:)];
[toolBar setItems:[NSArray arrayWithObjects:doneButton, nil]];
self.messageTextView.inputAccessoryView = toolBar;
I've added a UIToolBar
with a UIBarButtonItem
as inputAccessoryView for a UITextView
. It works fine but the UIBarButtonItem is touchable outside it's frame, perhaps 50 pixels outside to the right. It's no big deal but it annoys me. Anyone know why?
This is my code (ARC):
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
toolBar.barStyle = UIBarStyleBlack;
toolBar.translucent = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneWriting:)];
[toolBar setItems:[NSArray arrayWithObjects:doneButton, nil]];
self.messageTextView.inputAccessoryView = toolBar;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 iOS 6 中,它的表现似乎符合预期。
不错的提示:如果您希望按钮显示在右侧而不是左侧,请使用以下选项之一:
然后使用以下命令初始化工具栏:
In iOS 6 it seems to behave as expected.
Nice tip: If you want the button to appear on the right instead of the left, use one of these:
Then initialise the toolbar with:
如果工具栏中没有其他附近的按钮,工具栏似乎会将按钮的活动区域扩展到其范围之外。苹果工程师肯定认为,最好尝试猜测用户想要按的位置,而不是根本不做出反应。
The toolbar seems to expand the active area of the buttons beyond their bounds if there are no other nearby buttons in the toolbar. Apple engineers must think it is better to try to guess where the user intended to press rather than not react at all.
我希望它可以帮助您...
使用假项目来获取按钮上的精确捏合位置...
I hope it helps you...
Use Fake Item to get exact pinch location on Button...