Is there any way to animate uiview moving with cicle trajectory?
You will have to create a circular path and animate your view on the path. You can use UIBezierPath to create a circular path . Here is an example that does what exactly you want.
There are a couple of options. Probably the simplest is to place your view on a parent view, and then animate rotating the parent view around its Z axis.
I guess you could also build a transform that shifts your view, then rotates it, and animate the transform to different rotation values. I'd have to tinker with that. I know the first approach would be quick and easy to set up.
As the other poster said, you could also create a keyframe animation that uses a CGPath to animate your view along a curve that approximated the shape of a circle, but that would be much more work.
Related
I want get texture or image from UIVIew like screenshot. But without create CGContext, and draw UIView on this context. If this view display on screen, i think it contains this texture somewhere inside. How can I get this texture/image from UIView? How can I catch moment redraw this texture(E.g. change highliten button inside view)?
There isn't a texture stored for a rendered UIView. There will be a framebuffer under the hood somewhere but I don't think you can get at that.
Like you said, you can render a view's layer to a CGContext. This is easily done and I believe it's the only way of achieving what you want. What are your reasons for avoiding this approach? Perhaps you are trying to solve the wrong problem.
I have an image view that looks like a wheel. This view detects touch events on each of the colored sections.
The problem I have is that when I rotate this wheel, the UILabels on top of the view need to also be rotated so that the text is still horizontal and human readable.
What is the best way to rotate the labels while the parent view is being rotated?
This is what I am trying now and it does not rotate correctly...
CGAffineTransform textTransform = CGAffineTransformRotate(newTransform, newAngle * -1);
Presumably you are applying a rotation transform to rotate the wheel. If the labels are subviews of the wheel view, their centers are pinned in the right places to the wheel (because a view is located in its superview by its center), and they will travel around with it. At the same time, apply the inverse rotation transform to the labels. The rotation takes place around the center of each label. So each label stays in the right place and stays upright.
An afterthought - also make sure you're not using autolayout on these labels. Autolayout breaks view transforms.
Why using "pan" after rotate makes view go opposite way?
It seems these two gesture are use diffrent coordinate system? Rotation use the one is rotated,and pan use the normal one?
And if the view is rotated nearby 0' or 360 ',pan will be normal,and if the view is rotated more colse to 180',the "pan" will make view go opposite more.
Thanks.
The point is that in your handRotate method you are assigning a rotation transformation to your view. This entails a permanent (until you modify the transformation again) change in the way your view is displayed within its superview, and the rotation transformation will be always "added" to whatever other change you do to the geometrical properties of your view.
What explains the behavior you are seeing is the interplay between the position of your view and its anchor point, as explained in Layer Geometry and Transform.
In other words, the center property you are modifying when panning is the result of applying all the transforms that you have defined for your view. On the other hand, what you are trying to do when panning would require modifying the position of the view before the transformation are applied.
A way to go about this is reframing your code by using layers (CALayer) and modifying the layer position property instead of the view center. Like in:
recognizer.view.layer.position = ...
I think that this should fix it.
(You will need to import QuartzCore for that to compile).
Hope this helps.
I have two table view controllers. How can I make shadow like this?
Take a look at CALayer class from CoreAnimation framework. Here is a nice tutorial with examples: http://nachbaur.com/blog/fun-shadow-effects-using-custom-calayer-shadowpaths
Then you apply the shadow to the right tableview(however, it might be required embedding the tableview in container view)
The easy way if you don't know about core graphics is to make a gradient png and position/size it to the right of your cell, under everything else.
In UIBuilder, select the view containing the table. You may need to play around with the exact level of what you select. On the far right in the inspectors, is the View Effects inspector. There you can set a shadow, including the blur radius and offset. If you just set the shadow without either a blur radius or an offset, you won't see the shadow, since it will be directly behind your table.
You can create a drop shadow easily, using QuartzCore.
Code:
#import <QuartzCore/QuartzCore.h>
UIView *myView = <your view here>
myView.layer.shadowOffset = CGPointMake(5, 5);
myView.layer.shadowRadius = 5.0f;
That should do it.
Please note that, when setting the shadowOffset, using positive values will drop to the right and bottom, using negatives will do the opposite.
Ok, I have a View, and first, I want that as soon as the user touches the View (a rectangle in this case) and starts dragging around a line should be drawn, following the path of the finger. Later, when I call a specific method, I want the View to follow the line and of course the line to disappear.
My thought for drawing the line:
Add a UIPanGestureRecognizer to the view, and then AddLineToContext, then draw it.
Use the touchesBegan, etc. methods. But later, I have multiple Views in there, and I need to find out which one the user touched. (have fun, there will be between 1 and 15...)
And I still have no idea about the other thing.
For the purpose of drawing the path, you are on the right track. I would use the gesture recognizer out of the two options you have.
To make the rectangle follow the path the easiest method I can think of is to keep an array of x and y for each point you are passing trough (don't forget to remove the consecutive duplicates).
So, now that you have an array of points that describe the shape of the path you can start a timer, or better use CADisplayLink, that will set the position of the rectangle to each of the points in the array. This will make the rectangle follow the path.
If you want the rectangle to follow the orientation as well, you will need to use vectors to describe the direction in which the rectangle should head.
First you need calculate the distance between the rectangle's position and the point in which it should go next using:
then, when you know the distance you can use arcsine to get you the direction angle. Then simply rotate the rect by that value.
Be careful at angle representation (pi vs degrees) and at the coordinates system.