gpt4 book ai didi

ios - UITap 手势仅适用于一种 View

转载 作者:行者123 更新时间:2023-11-28 21:55:59 25 4
gpt4 key购买 nike

我在 View Controller 中有以下代码:

@interface QuizController ()

@property (weak, nonatomic) IBOutlet UITextView *questionText;
@property (weak, nonatomic) IBOutlet UITextView *one;
@property (weak, nonatomic) IBOutlet UITextView *two;
@property (weak, nonatomic) IBOutlet UITextView *three;
@property (weak, nonatomic) IBOutlet UITextView *four;

@property(strong, nonatomic) NSMutableArray* possAnswers;
@end

@implementation QuizController

- (void)viewDidLoad {
[super viewDidLoad];
[self.manager setupGame];
self.possAnswers = [[NSMutableArray alloc] initWithObjects:@"a", @"b", @"c", @"d", nil];

}

//This listens for a tap on any of the TextViews and sets the background to Blue

- (IBAction)fourTapped:(id)sender {
NSLog(@"There's been a tap!");
[self blankBoxes];

if( [sender isKindOfClass:[UITapGestureRecognizer class]] )
{

UITapGestureRecognizer* tgr = (UITapGestureRecognizer*)sender;
UIView* view = tgr.view;
if( [view isKindOfClass:[UITextView class]]){
UITextView* tv = (UITextView*)view;
NSLog([tv text]);
[tv setBackgroundColor:[UIColor blueColor]];
}

}

}

-(void)blankBoxes
{
[_one setBackgroundColor:[UIColor whiteColor]];
[_two setBackgroundColor:[UIColor whiteColor]];
[_three setBackgroundColor:[UIColor whiteColor]];
[_four setBackgroundColor:[UIColor whiteColor]];
}

但是,无论点击哪个 View ,唯一突出显示的 UITextView_one。我不明白这是为什么。如果有人能向我指出这一点,我将不胜感激。

最佳答案

手势识别器仅附加到一个 View 。这是设计使然。如果您想要一个单一的手势识别器来识别多个 View 上的点击,您必须将它附加到一个公共(public)的、封闭的 super View ,然后查看点击坐标并找出哪个 View 被点击。

通常,您只需为需要响应点击的每个 View 创建不同的手势识别器。

关于ios - UITap 手势仅适用于一种 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26555551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com