how can I change the UIView background colour by a SwipeGesture? e.g. Green for a Left Swipe and Red for a Right Swipe. Thank you very much.
code doesn't work:
- (void)viewDidLoad {
self.view.backgroundColor=[[UIColor alloc]initWithRed:24.0/255 green:96.0/255 blue:120.0/255 alpha:0.5];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)];
[imageView setUserInteractionEnabled:YES];
[super viewDidLoad];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
// Setting the swipe direction.
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
// Adding the swipe gesture on image view
[self.view addGestureRecognizer:swipeLeft];
[self.view addGestureRecognizer:swipeRight];
}
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
self.view.backgroundColor=[[UIColor alloc]initWithRed:138.0/255 green:24.0/255 blue:47.0/255 alpha:1.0];
NSLog(@"Left Swipe");
}
if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
self.view.backgroundColor=[[UIColor alloc]initWithRed:24.0/255 green:96.0/255 blue:120.0/255 alpha:1.0];
NSLog(@"Right Swipe");
}
}