问题
I want to disable UICollectionViewController's autorotation whenever there's a finger on the screen, as the iPhone photo app does.
How to do that?
- If use tap gesture, how to distinguish different touch states? (The state should be
touching
, even after finger moving.) - If use
touchBegan:withEvent:
, where to put that code? (The hit view can be any subview of UICollectionView.)
回答1:
I would set a flag in touchesBegan
and clear it in touchesEnded
. Then in your shouldAutoRotate
method you can check the flag and return false if the flag is set.
Something like this:
// In your UICollectionView subclass:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Do stuff
...
canRotate = NO;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// Do stuff
...
canRotate = YES;
}
// In your UICollectionViewController:
-(bool)shouldAutorotate
{
return(canRotate);
}
来源:https://stackoverflow.com/questions/22487121/how-to-detect-touch-on-uicollectionview