How can I rotate an image similar to how it's done in the standard gallery feature? The standard gallery has wheel which the user can tap with one finger and swipe from left to right and turn image to 45 degrees.
Here a screenshot of what I mean:
Try this code for rotation.
CGAffineTransform newTransform = CGAffineTransformMakeRotation((CGFloat)(angel));
self.imageView.transform = newTransform;
try this code for rotation.
CGFloat degrees = 45.0f; //the value in degrees
CGFloat radians = degrees * M_PI/180;
imageView.transform = CGAffineTransformMakeRotation(radians);
I think you need single finger rotate.
Here is library you can go with:
https://github.com/zedoul/ZDStickerView
Related
I have a UIView in my view. Right now I have a button moving the UIView on it's y axis. Here is my code
CGRect frame2 = self.test22.frame;
frame2.origin.y -= 1.f/[UIScreen mainScreen].scale; //however many pixels to the right..
self.test22.frame = frame2;
But how can I rotate it? Except using the x or y axis. I want to be able to move the UIView by rotation by 1.f.
To Rotate the UIView create the object of UIView (*view) and make transform on it
Lets to rotate the view 90 degree use below code
CGAffineTransform r_transform = CGAffineTransformIdentity;
r_transform = CGAffineTransformRotate(r_transform,DegreeYoRadians(90));
view.transform = r_transform;
Welcome to SO. You want to look at the UIView method animateWithDuration, and the view's transform property. You'd apply a rotation transform to the view in your animation block. Note that if you change a view's transform, you should not read or write the frame property. Instead use the center property to change the position and the bounds.size property if you need to change the size.
Your code might look like this:
[UIView animateWithDuration: .25
animations: ^
{
self.test22.transform = CGAffineTransformMakeRotation(M_PI/2);
CGPoint center = self.test22.center;
center.y -= 1;
self.test22.center = center;
}
];
EDIT:
I have no idea what you mean when you say "I want to be able to move the UIView by rotation by 1.f." Rotating a view is not moving it, it's rotating it. And rotation is expressed as an angle, not a value like "1". Furthermore, the angle is in radians, where π is 180 degrees, π/2 is 90 degrees, and 2π is a full-circle rotation (or no change, since it puts the rotation back at it's original value.) You have to think in terms of fractions of 2π when you do rotations. Or you can use degrees and convert to radians, where:
degrees = radians * 180/π
Also, your code that moves the view will only change the view's position by half a point on retina displays which doesn't make much sense.
I have a large UIScrollView canvas and I want completely rotate this scrollView. For this I try:
scrollView.transform = CGAffineTransformMakeRotation(90.0)
but in this case I get:
it's not 90 deg. And in my opinion it rotate in 3D. How can I rotate it properly?
CGAffineTransformMakeRotation takes in radians, not degrees.
Try this:
import Darwin
scrollView.transform = CGAffineTransformMakeRotation(M_PI / 2.0)
I want to rotate image (UIImageView) from particular side (for ex. Right Side).
I know through :-
float degrees = 20; //the value in degrees
imageView.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);
but it rotates from center.
I want to rotate my UIImageView from one particular side (i.e. Left side will be at its place, and right side will change its position).
Thanks in advance.
Try to use anchorPoint property.
imageView.layer.anchorPoint = CGPointMake(0, 0);//Top left angle
float degrees = 20; //the value in degrees
imageView.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);
Do not forget to add QuartzCore framework.
Rotate from center and move UIImageView where you will. Result will be the same as rotating from right edge.
I want to rotate a UIImageView, and I am using this code:
-(IBAction)rotateImageView:(id)sender{
photoView.transform = CGAffineTransformMakeRotation(M_PI); //rotation in radians
}
The code works. when I press the button, the image rotates 180 degrees, but if I press it again it doesn't rotate back to its original position, but it stays still. why??
Because you are applying the same transform to the view again, without taking into account any existing transform.
Try this:
photoView.transform = CGAffineTransformRotate(photoView.transform,M_PI);
you have to rotate the imageView from the current rotation to make it original
use this code
CGAffineTransformRotate(photoView.transform, M_PI);
in my app I have an imageview, its name is arrow and I rotate it of 180 degrees in this way:
arrow.transform = CGAffineTransformMakeRotation(M_PI);
it work fine, but now I want that this imageview return in the original position; what's the value taht I should set to obtain it?
To make it return to it's original position, just do this:
arrow.transform = CGAffineTransformMakeRotation(0);
In degrees, 0 radians is 0 degrees, so it should return to its original position.
Try setting the transform property back to the identity matrix. i.e. CGAffineTransformIdentity
Swift3:
arrow.transform = CGAffineTransform(rotationAngle: rotation);
where rotation is the angle to rotate in radians.