In my app I wanted to position in the center of the screen a UIImage, with the shape of a circle. Then I wanted the user to be able to rotate the image buy touching one specific point on the circumference of the circle, and dragging, just like a wheel, but I have no idea where to start form.
I know I can use the touches began, moved, and ended, but how can I fix a point?
You can adjust the origin property of your UIView. This should force the rotation around that point.
Related
What is the benefit or purpose to change the CALayer position, which is by default in center, don't it suppose to be a center of CALayer? Whats the point changing a center point to bottom right or any other, because bottom right can't be the center of a square.
It's helpful for things like rotation where you may want to rotate around a particular point instead of the center
I'm trying to make a circular UIView animate in a particular direction until it collides with the borders of the view (which is full screen, so basically the borders of the device), at which point it will reflect off it and continue on its way infinitely. However, I'm not really sure how to pose my question, so I'm having trouble finding any information on it. I already have the view, the direction it will move in, and its velocity. I'm just not sure how to handle an animation like that.
Any advice is much appreciated! Thanks!
Use a CADisplayLink to continuously update the position of the view, synced with the refresh rate of the screen. The update method that that display link triggers will take into account the current x and y velocity of the view and update the frame based on it. If at ever point the x- or y-coordinate goes under or over a limit (0 or screen width/height), reverse the appropriate velocity value and recalculate the position.
I have a sprite looking like a pencil. I want to draw a line when user touches this sprite.
I am able to draw the line on touch location & move the sprite accordingly. The problem is that the line is not drawing from tip of the pencil which lies at left bottom of the sprite.
I don't want to move the left bottom edge of sprite under the touch point because then user will not be able to see the tip but instead shift the coordinates to draw to the tip itself.
I tried setAnchorPoints but that's not helping. Anyone tried this or has better ideas please do share. Thanks.
You could draw the line at something like pencil.position.y - (pencil.sizeofthesprite.y / 2) and it should be fine.
How to rotate triangle image of speech bubble on the surface of bubble ? triangle image can scale and rotate with the touches and dragging.
What you can do is clip the triangle part of the bubble form the original image, make it into a UIImageView and place it just as if it is a part of the bubble. Then use this UIImageView and make it scale , rotate etc likewise according to UIGestures or UITouch whichever is easier for you along with the bubble. If you want any code help for that please ask. Thanks :)
I'm drawing a few circles, each filled with an image. When the user pans I'd like to scale/resize the circles. So I called drawRect again and again, redrawing every GCRect until the gesture was completed - of course the animation was very choppy. In my case a UIScrollView doesn't fit the needs, because I don't want to scroll, but to scale the circles while the user is panning.
Is there any way except using OpenGL ES to implement this functionality?
Do you really need custom drawing for this? You can easily clip an image to a circle without drawRect.
Without -drawRect:
Using Core Animation you can set the corner radius of a layer. If all you want is to show an image inside a circle then you can put the image in an image view with a square frame and set the corner radius of the image views layer to half the width of the frame.
Now each time the user drags you can change the bounds and the corner radius of the image views layer. This will make it look like the circle becomes bigger/smaller.
If you require custom drawing
Maybe you are doing some custom shadows or blending that can only be done with Core Graphics. If so, you could apply a scale transform and stretch the image while the user is dragging their finger and only redraw once the finger lifts from the screen. That will be much, much cheaper and is also very easy to implement. Just create a scale transform (CGAffineTransformMakeScale(xScale, yScale);) and set it as the transform on the view with the circle (this will only work if each circle is its own view).
Note: You can still use the same trick (scaling while dragging and then redrawing) if you use the corner radius approach if you require the extra performance.