Reception of touch gestures only on a part of vision

I have a UIImageView in a view controller. Is it possible to make certain areas of the image visible?

Example: I have a map image. Make only POIs available. Not the whole image. Is it possible?

+4
source share
4 answers

You can use the handleGesture method. First you need to create a location to get the strokes, and you have to compare it with the touch location in the delegate method, as shown below:

 CGRect locationRect; 

in viewdidload

 locationRect = CGRectMake(CREATE A FRAME HERE); 

next delegate method

 - (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer { CGPoint p = [gestureRecognizer locationInView:self.view]; if (CGRectContainsPoint(locationRect, p)) { NSLog(@"it inside"); } else { NSLog(@"it outside"); } } 
+9
source

Yes, it is possible, but you must ask yourself whether it is worth it or not. If it were me, I would add an object of interest to the map and attach a gesture recognizer to it. However, if you want to switch to a different route, you can explore the following UIGestureRecognizerDelegate method

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 

This will tell if this gesture should handle the given touch. You can filter it based on your POI.

+2
source

Yes, I can help you. I recently tried to create my own segmented control in which I had three views.

At the time when I was playing with the first half of my gaze. But the rest is half the answer. I checked it, and the result is useful to you now.

My segment frame:

segment.frame = CGRectMake (0, 0, 300, 100);

And the UIView frame:

view1 = [[UIView alloc] initWithFrame: CGRectMake (10, 80, 100, 40)];

Then I changed the frame height to 200, and then it worked:

segment.frame = CGRectMake (0, 0, 300, 200);

** SO IF YOU WANT TO DO, ONLY ACKNOWLEDGMENT ONLY FOR PART OF YOUR LOOK, REDUCING THE HEIGHT OF YOUR FRAME WHICH IT **

0
source

Thanks to manujmv, I was able to figure out Swift 3's implementation of the custom gesture area . In my case, I create 50-dot stripes on each side of the window to transition from one VC to another. But this should be fairly easy to reuse for any other application:

 class ViewController: UIViewController { ... var mySensitiveArea: CGRect? ... override func viewDidLoad() { ... let screenWidth = UIScreen.main.bounds.size.width let screenHeight = UIScreen.main.bounds.size.height mySensitiveArea = CGRect(0, 0, 50, screenHeight) let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(self.handleGesture(_:))) swipeGesture.direction = UISwipeGestureRecognizerDirection.right self.view.addGestureRecognizer(swipeGesture) } } //Function for determining when swipe gesture is in/outside of touchable area func handleGesture(_ gestureRecognizer: UIGestureRecognizer) { let p = gestureRecognizer.location(in: self.view) if mySensitiveArea!.contains(p) { print("it inside") showMainViewController() } else { print("it outside") } } //Segue to Main VC func showMainViewController() { self.performSegue(withIdentifier: "toMain", sender: self) } 
0
source

Source: https://habr.com/ru/post/1488200/


All Articles