在我的应用程序中,不包含任何 UIElements,例如 facebook 按钮、twitter 按钮、注销按钮、带有手势的 imageview
。
`
facebookBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[facebookBtn setImage:@"facebook.png"];
[facebookBtn addTarget:self action:@selector(switchToFacebookShare) forControlEvents:UIControlEventTouchUpInside];
[facebookBtn setFrame:CGRectMake(0, 50, 24, 24)];
[self.view addsubview:facebookBtn];`
`twitterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[twitterBtn setImage:@"facebook.png"];
[twitterBtn addTarget:self action:@selector(switchToTwitterShare) forControlEvents:UIControlEventTouchUpInside];
[twitterBtn setFrame:CGRectMake(0, 100, 24, 24)];
[self.view addsubview:twitterBtn];`
`imageTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionTapping:)];
[imageTapGesture setNumberOfTapsRequired:1];`
`sectionPortraitImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[sectionPortraitImageView setUserInteractionEnabled:YES];
[sectionPortraitImageView addGestureRecognizer:imageTapGesture];
[contentView addSubview:sectionLandscapeImageView];`
像这样我添加了所有元素 当用户一次单击所有按钮时,所有三个功能都将起作用。 这里只需要做一项操作。
如何解决这个问题?
最佳答案
一次处理多个触摸问题并设置单独的属性
[sectionLandscapeImageView setExclusiveTouch:YES];
//处理所有 subview 的多次触摸用户交互
-(void)multipleTouchHandling
{
self.view.multipleTouchEnabled=NO;
self.view.exclusiveTouch=YES;
for(UIView* view1 in self.view.subviews)
{
if([view1 isKindOfClass:[UIButton class]])
{
UIButton* btnVw = (UIButton*)view1;
[btnVw setExclusiveTouch:YES];
}
}
}
关于ios - 如何同时禁用屏幕上的多个用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27653214/