I have UIImageView (square) with triangle picture.
1) When i touch to edge of UIImageView I should be able to rotate it.
How can i detect my touch in three different edges? (my picture is triangle)
2) And i need to rotate UIImageView and how can I detect area for rotate?
Don't forget about triangle. The center of the triangle is different from the center of the UIImageView.
I use this function to detect UIImageView area, but it's square area, not triangle.
I have UIImageView (square) with triangle picture.
1) When i touch to edge of UIImageView I should be able to rotate it.
How can i detect my touch in three different edges? (my picture is triangle)
2) And i need to rotate UIImageView and how can I detect area for rotate?
Don't forget about triangle. The center of the triangle is different from the center of the UIImageView.
I use this function to detect UIImageView area, but it's square area, not triangle.
I had to solve this exact problem for our company's (Mac) kaleidoscope application, ScopeWorks.
I did some searching on the web, and the trick is to see if the point you're testing is on the right or left of all 3 line segments of the triangle. Here's the code I came up with:
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
As expected, I encountered with another problem.
I want to rotate my triangle, but center of my triangle isn't center of UIImageView. Picture here (triangle can be versatile):
I just to know how to rotate UIImageView, not triangle. Could you help with this?
As expected, I encountered with another problem.
I want to rotate my triangle, but center of my triangle isn't center of UIImageView. Picture here (triangle can be versatile):
I just to know how to rotate UIImageView, not triangle. Could you help with this?
You rotate the UIImageView, but need to change the center of rotation.
If you're rotating the image view by applying a rotation transform, you just need to shift the anchor point of the rotation.
What you do is first calculate the center of the triangle (in image coordinates, where 0,0 is the top right of the triangle)
Then you need to calculate where that point falls in your image as a value from 0 to 1 for height and width centerpoint.x = 0 at the left edge and = 1 at the right edge.. centerpoint.y = 0 at the top and 1 at the bottom.
Finally, you need to set the anchorpoint of the view's layer to that calculated centerpoint value (take a look at the anchorPoint property of CALayer for more info)
Now when you apply a rotation transform to the view's CALayer, it rotates around that anchor point instead of it's center.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
What i did:
The triangle rotates for 10 degrees after every tap, but with a shift (its a problem).
What i need:
1) I need to rotate triangle without shifts after the tap to triangles edges (first of all without shifts, I now how to detect edges of triangle)
2) Move the triangle with the tap of center. (the problem here, when the triangle moves, all coordinates changed and my UIImageView stretches in all directions)
What i did:
The triangle rotates for 10 degrees after every tap, but with a shift (its a problem).
What i need:
1) I need to rotate triangle without shifts after the tap to triangles edges (first of all without shifts, I now how to detect edges of triangle)
2) Move the triangle with the tap of center. (the problem here, when the triangle moves, all coordinates changed and my UIImageView stretches in all directions)
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Sorry, i solves this ) i forgot that the square or rectangle or rhomb - it's two triangles =)
But for knowledge base, maybe you know function to detect point in square?
Sorry, i solves this ) i forgot that the square or rectangle or rhomb - it's two triangles =)
But for knowledge base, maybe you know function to detect point in square?
If the rectangle is not rotated, just check to see if the x coordinate is between the leftmost and rightmost edges and the y coordinate is between the top and bottom edges of the rectangle.
If it's rotated, dividing it into 2 triangles and using triangle tests is probably the way to go.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.