- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想添加一个 *UITapGestureRecognize*r 到我的 UITextView,因为我想关闭 TextView 所在的“弹出窗口”。所以我想要,当点击 T*extView* 时,将调用 Popup 类的“隐藏”方法。我尝试了如下方法,但由于某种原因它不起作用:
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(show)];
[gr setNumberOfTapsRequired:1];
[viewText addGestureRecognizer:gr];
我也不想为它创建一个子类,因为我需要调用“父”方法“隐藏”。
也许您现在可以很好地解决该问题。
预先感谢您。
最佳答案
您不应该使用 UITapGestureRecognizer,而应使用 UITextFieldDelegate。
您可以在这里阅读:
您基本上需要添加UITextViewDelegate 像这样到你的 .h 文件 -
@interface MyViewController : UIViewController<UITextViewDelegate>
然后将您的 Controller 指定为委托(delegate):
viewText.delegate =self;
现在使用一种委托(delegate)方法,也许:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
// Do what you need to do...
}
编辑
我可以考虑另外两种方法:
您可以使用:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:textView];
//Checks if the tap was inside the textview bounds
if (CGRectContainsPoint(textView.bounds, location)){
//do something
}
}
祝你好运
关于iphone - 将 TapGestureRecognizer 添加到 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6249222/
当我点击第一个 ViewController 中的 UIImageView 时,我正在调用另一个类中的函数: let tapGestureRecognizer = UITapGestureRecogn
所以我有一个自定义 View ,我在 View Controller 的 for 循环中创建了许多 View 。在创建它们时,我对每个它们调用此方法: -(void)setUpStuff{ /
您好,我没有卡片可以用来解决这个问题。我们开始吧。 我有这五个 imageview,这是第一个 imageview 的声明,但基本上它们有相同的声明 @IBOutlet weak var first
嗨,在 viewDidLoad 的主 WiewController 中,我设置了一个 UIGestureRecognizer *recognizer = [[UITapGestureRecognize
我有一个问题。我创建了一个示例项目来解决它,但没有成功。我创建了一个负边距的按钮,位于导航栏的中间。水龙头仅适用于下部。 MainPage.xaml:
我正在 iOS 6.1 上为 iPad 开发一个应用程序。我的 CALayer 和 TapGestureRecognizer 有问题。 我有 7 个 CALayers 形成彩虹(每一层都是一种颜色)。
在我的应用程序中,我有一张图片和一个 UITextView . 我创建了一个 UITapGestureRecognizer对于这两种 View ,但问题是无论我在屏幕上单击什么位置,只有与 UITex
我对 UITableViewCell 进行了子类化。我尝试添加手势识别器,但点击它时没有任何反应。 class MessagesTableViewCell: UITableViewCell {
谁能帮我解决这个错误?不确定它要求什么... TapGestureRecognizer Syntax override func viewDidLoad() { super.viewD
我正在尝试使用 Firebase 构建一个聊天应用程序。我正在尝试实现点击手势,以便在键盘打开时关闭键盘。不幸的是,当您点击屏幕时没有任何反应。我尝试了不同的东西,结果相同。如果有人知道它不起作用的原
这段代码的目的是将 UIView 动画到屏幕上的某个位置。不幸的是,它根本没有注册水龙头。我是否应该将委托(delegate)设置为我的设置中的某些内容?任何帮助将不胜感激! public class
我已经设置了一个点击手势识别器并将识别器添加到 uibutton。该按钮有一个背景图像。当我点击按钮时,它根本不突出显示,我唯一能做的就是更改它的 alpha 值。 UITapGestureReco
我想添加一个 *UITapGestureRecognize*r 到我的 UITextView,因为我想关闭 TextView 所在的“弹出窗口”。所以我想要,当点击 T*extView* 时,将调用
我正在尝试实现 TapGestureRecognizer,它将在 ViewModel (xaml.cs) 中调用,而不是在 View 类中...... 这是 xaml 文件中的示例代码:(IrrigN
我有一个 XF 应用程序,其中定义了以下 Collection View 。第二个标签有一个 TapGestureRecognizer,当我点击标签(在 Android 上尝试这个)时,它不会在模型中
我有一个 XF 应用程序,其中定义了以下 Collection View 。第二个标签有一个 TapGestureRecognizer,当我点击标签(在 Android 上尝试这个)时,它不会在模型中
所以我有一个像照片库一样的应用程序,我正在实现用户删除图像的能力。这是设置:我有 9 个 UIImageView、imageView、imageView2 等。我还有一个“编辑”按钮和一个 tapGe
我正在 swift 3.0 中开发一个项目,我有 UIViewController 来填充一些文本字段。因此,我使用 TableView 作为下拉菜单,一旦选择一行,它将被分配给 UILabel。此外
我正在 swift 3.0 中开发一个项目,我有 UIViewController 来填充一些文本字段。因此,我使用 TableView 作为下拉菜单,一旦选择一行,它将被分配给 UILabel。此外
我有一个 UIToolbarButton,它有一个 UIButton 来保存图像。现在,当我点击这个 UIToolbarButton 时,我想在当前 View 中打开另一个 View 。 我的代码:
我是一名优秀的程序员,十分优秀!