I would like to have a UIView that blocks subviews for responding to gestures. The main purpose is to block the user interface from touches and gestures while data is validated in the server. Once the request has been processed it will removed from the top that blocking UIView.
How can this be accomplished? What I have so far is the following:
@interface TableViewController ()
@property (weak, nonatomic) IBOutlet UITableView *table;
@property (strong, nonatomic) IBOutlet UIView *blockingScreen;
....
@end
The implementation:
@implementation PlayListViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_table.dataSource = self;
_table.delegate = self;
// Blocking screen should take all the screen.
// Unfortunately, when it is displayed it gets the table size , ??
_blockingScreen = [[UIView alloc] initWithFrame:CGRectMake(0,0,
[[UIScreen mainScreen] applicationFrame].size.width,
[[UIScreen mainScreen], applicationFrame].size.height)];
_blockingScreen.userInteractionEnabled = NO;
[self loadGestureRecognizer];
}
- (void) loadGestureRecognizer
{
// Long press gesture recognizer declaration
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognized:)];
// Swipe gesture recognizer declaration
UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGestureRecognizer:)];
swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
// Attach gesture recognizers
[_songsTable addGestureRecognizer:longPress];
[_songsTable addGestureRecognizer:swipeLeftGesture];
}
// At some point, the gesture recognizer will be invoked
// In this case when swiping a table row
- (IBAction)swipeGestureRecognizer:(UISwipeGestureRecognizer *)sender
{
// Do things
...
// Preparing for doing Http request
// I want to display the blockingScreen on top of all views
// so no gestures are recognized.
[_table addSubview:_blockingScreen];
[_blockingScreen setBackgroundColor:[UIColor blackColor]];
_blockingScreen.alpha = 0.3;
// Bring to front
[_table bringSubviewToFront:_blockingScreen];
// To avoid gesture recognition I'm forced to do the following
_table.userInteractionEnabled = NO;
}
@end
At some point the swipeGestureRecognizer will be invoked by a swipe gesture. That works just fine. The blockingScreen appears to be on top of the table view (deeming just the table) and does not block any gestures.
I'm quite new to objective-c and xcode so explanations, tutorial or external resources are all welcome. I have already read some other answers in SO like How to disable touch input to all views except the top-most view?, Container View Receives Touches Instead of Subview on iPad and tried:
_blockingScreen.userInteractionEnabled = NO;
but also to
_blockingScreen.userInteractionEnabled = YES;
and don't see any difference.
Anyone has any idea?