点击iPhone屏幕上任意位置的工具提示

时间:2018-05-11 20:46:18

标签: ios objective-c iphone uibutton tooltip

我正在开发一个应用程序,我正在iOS应用程序上实现工具提示。在我的应用程序中,我希望当用户点击屏幕上的任何其他位置时,工具提示会被取消。 在屏幕上,可以有其他按钮,文本字段,下拉列表或只是没有。我希望当用户点击其中任何一个(基本上在屏幕上的任何位置)时,工具提示被解雇。请建议我该怎么做

1 个答案:

答案 0 :(得分:0)

一种简单的方法是,只要您显示工具提示,就可以在所有内容上添加透明按钮。在视图控制器中添加以下代码。

@interface yourViewController ()

@property (strong, nonatomic) UIButton *tooltipButton;

@end

- (void)showTooltip {
    // your code to show the tooltip goes here

    self.tooltipButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.tooltipButton.backgroundColor = [UIColor clearColor];
    self.tooltipButton.frame = self.view.bounds;
    [self.tooltipButton addTarget:self action:@selector(tooltipButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.tooltipButton];
}

- (void)tooltipButtonPressed {
    [self.tooltipButton removeFromSuperview];

    // your code to remove the tooltip goes here
}
相关问题