IOS - How to show an upside "uʍop" text? - iphone

In the IOS GUI, I would like to place a textbox but it has to be upside down.
How could I do this?

You could try and use CGAffineTransform to rotate it 180 degrees
#import <QuartzCore/QuartzCore.h>
#define degreesToRadians(x) (M_PI * x / 180.0)
[textbox setAnchorPoint:CGPointMake(0.5, 0.5)];
[textbox setTransform:CGAffineTransformMakeRotation(degreesToRadians(180))];
By setting anchorPoint to 0.5 , 0.5 means we want the rotation apply to the center of the textbox
More explanations with details can be found here

Related

UIimageView rotate around a center point of another UIImageView

I have two images.
One image is rectangle
second is triangle
i want to rotate tringle image from the center point of rectangle image using one finger or touch event.
Well, the math for this will get decently complex if you wish for the image to rotate in a circle of any size around the rectangles center point, but a good start would be to define the anchor point of the triangle image view, e.x.
#import <QuartzCore/QuartzCore.h>
#define degreesToRadians(x) (M_PI * x / 180.0)
[[triangleImageView layer] setAnchorPoint:CGPointMake:(0.5,0.0)];
[UIView animateWithDuration:1.0 animations:^{
[triangleImageView setTransform:CGAffineTransformMakeRotation(degreesToRadians(90))];
}];
Finally i found that i have to use [view.layer setAnchorPoint:CGPointMake(0.5, 0.5)]
and it solve my problem.

What is angle in CATransform3DRotate method?

I am working on a application showing my heading and bearing to the location I want to go. I want to display a arrow direction to the direction user should have his heading to rich the desire location. There is nothing to get worry about this. What I want to do is I have degrees.. 0-360.
When I pass these degrees to the angle in bellow method this react strange. The Image get totate more than once.
I tried to get radians from the degrees and than tried but no success.
All I want is I have float value range between 0-360 and I wanted to rotate my image only once a 369 degree rotation.
I have passed radians too. For converting degrees to radians I used:
float radian = degrees * M_PI / 180
But this is also having same issue. All I want is image show work like a compass for all 360 degrees.
How to get angle for this method:
CATransform3DRotate (CATransform3D t, CGFloat angle, CGFloat x, CGFloat y, CGFloat z)'
Thank you in advance
You should pass radians there. For example, this will rotate image on 180 degrees:
switcher.transform = CGAffineTransformMakeRotation(M_PI);
if you have problems with converting degrees to radians, you can use following macroses:
#define DegreesToRadians(degrees) (degrees * M_PI / 180)
#define RadiansToDegrees(radians) (radians * 180 / M_PI)

How to rotate a UIbutton in Xcode + IB?

I am writing an iPhone programer, and
I want to make a button with is rotate 180 degree, I try to use the multi-touch track pad to rotate a UIbutton, but it don't success, how can I do it? or I need to do it by code?
You can't do it from Interface Builder. You have to rotate it from your code, using the transform property of your UIButton, which is a CGAffineTransform struct.
You can use the CGAffineTransformMakeRotation() to set it.
myButton.transform = CGAffineTransformMakeRotation( ( 180 * M_PI ) / 180 );
The first 180 in the code is the angle in degrees. The operation converts it to radians.
I was wanting to do this same thing - rotate a button 180 degrees when tapped - but do it using an animation. Neurofluxation's answer does the 180 degree rotation with an animation, but it isn't permanent. Macmade's answer does the 180 degree rotation, but doesn't do it with an animation. So if you're like me and would like to do a 180 degree rotation with animation use this code:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.35];
// (180 * M_PI) / 180 == M_PI, so just use M_PI
myButton.transform = CGAffineTransformMakeRotation(M_PI);
[UIView commitAnimations];
As well, if you want to rotate back to the starting position (ie 0 degree rotation) then put the following in between the animation code like above:
myButton.transform = CGAffineTransformMakeRotation(0);
As to a use case for such a button, Evernote's show/hide keyboard button does a really slick 180 degree rotation which can be recreated using the above code.
Well, here we go:
CABasicAnimation *halfTurn;
halfTurn = [CABasicAnimation animationWithKeyPath:#"transform.rotation"];
halfTurn.fromValue = [NSNumber numberWithFloat:0];
halfTurn.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
halfTurn.duration = 0.5;
halfTurn.repeatCount = 1;
[myButton addAnimation:halfTurn forKey:#"180"];
Hope that helps... Im typing from my PC though, not my Mac - So I hope that's right!

rotating View in angle?

i want to rotate my UIview to particular angle and stop that rotation in that angle.any help pls?
To rotate a UIView, change its .transform property.
theView.transform = CGAffineTransformMakeRotation(M_PI * 25 / 180);
Use UIView animation block to animate the rotation, as usual.

Is there a way to draw UILabel diagonally?

How do you draw text on a diagonal? In other words, a horizontal UILabel that's rotated, say, 45 degrees?
// rotate 45 degrees
label.transform = CGAffineTransformMakeRotation(M_PI / 4);
You may want to do this before adding the label to its parent view.
You can use a CGAffineTransform to rotate the view.
myLabel.transform = CGAffineTransformMakeRotation(45 * M_PI / 180);
Why no one mentioned M_PI_4 (constant for PI/4)?
myLabel.transform = CGAffineTransformMakeRotation(M_PI_4);
It's the fastest way 'cause it does not require division :)
http://developer.apple.com/library/ios/#documentation/system/conceptual/manpages_iphoneos/man3/math.3.html
You can .transform the label, e.g.
theLabel.transform = CGAffineTransformMakeRotation(M_PI / 4); // pi/4 = 45 degrees.
For Swift 3:
label.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 4))