Pip*_*iks 4 iphone objective-c ipad ios
如何在 UICollectionView 上禁用多点触控?
我想同时禁用两个单元格的选择。
我试过这个,但它不起作用:
self.collectionView.multipleTouchEnabled = NO;
self.collectionView.exclusiveTouch = YES;
Run Code Online (Sandbox Code Playgroud)
谢谢你。
您可以在第一次调用didSelectItemAtIndexPath后将布尔标志设置为 true,如果标志为 false(第二次调用该方法)则从该方法返回。从显示的视图返回后,您可以将标志设置回 false 以再次启用对该方法的单个调用(第一个调用)。
在您的viewDidAppear 中,将标志设置为 FALSE(未进行任何触摸)
然后在你的didSelectItemAtIndexPath
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if(self.flag==TRUE){
return;
}
// This will set the flag to TRUE the first time the method is called
self.flag=TRUE;
// the rest of your code: display the view
}
Run Code Online (Sandbox Code Playgroud)
假设您已经在类中声明了一个标志实例变量。
* Swift4 代码更新 *
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if flag { return }
// This will set the flag to TRUE the first time the method is called
flag = true
// the rest of your code: display the view
}
Run Code Online (Sandbox Code Playgroud)