user2557607
user2557607

Reputation: 81

Checking the position in ios

If I add a Pan Gesture Recognizer to the view and put down this code

recognizer.view.center.x > view.bounds.size.width

It is claimed that it can check whether it has passed half of the view yet.

What is the meaning of recognizer.view.center.x?

Upvotes: 0

Views: 61

Answers (2)

TeemoThunder
TeemoThunder

Reputation: 31

recognizer.view returns the view that the pan gesture recognizer is attached to (the view which you added the recognizer to), and recognizer.view.center.x returns the x-axis value of the centre of the view (essentially half of the width).

As far as I can understand, recognizer.view.center.x > view.bounds.size.width will never be true because half of the width will never be larger than the width itself.

I assume you are trying to find whether if the point of touch has passed the middle of the view on the x-axis, try the following:

[recognizer locationInView:view].x > view.center.x

Similarly, if you want to find out if it has passed below the middle of the y-axis:

[recognizer locationInView:view].y > view.center.y

Upvotes: 2

rmaddy
rmaddy

Reputation: 318824

Follow the values.

  1. recognizer is the pan gesture.
  2. view is the view the recognizer has been assigned to.
  3. center is the view's center point
  4. x is the center's x coordinate.

All of this can be seen by reading the reference documentation for each class. UIPanGestureRecognizer extends UIGestureRecognizer which is where you will find details about the view property. Simply drill down from there.

Upvotes: 1

Related Questions