Rotate a CGRect

hello!
I have a CGRect called circleRect,
how can I rotate this CGRect so that the pivot-point/axis that it is rotating around is the center of the rect
THANKS!

Have you tried [CGRectApplyAffineTransform|http://developer.apple.com/iphone/library/documenta tion/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html#//appl e_ref/c/func/CGRectApplyAffineTransform]?

Similar Messages

  • Rotation nighmare

    Hi!
    Here is my nighmare...
    I have a landscape application... at some point I need to display a portrait UIImagePickerController. So, I temporarily rotate the view 90 degrees using this...
    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(0);
    self.view.bounds = CGRectMake(0.0, 0.0, 320, 480);
    and bring the UIImagePickerController.
    My nighmare starts when I dismiss the controller. At this point I need to rotate the view back to landscape. So, I use this code...
    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
    XXXX
    [picker dismissModalViewControllerAnimated:YES];
    where XXXX is the code to rotate the view back. This is my nightmare. I have tried trillions of combinations of codes and variations there and nothing brings my view back to landscape. Depending on the code I put there I have one of two things: a black screen or a view on the same place it was when I rotated it from landscape to portrait before showing the UIImagePickerController.
    So, my question is: what code should I put there?
    I noticed that when I have a black screen is because the view is outside the screen. When this happens I check the frame coordinates are something like (80, -80, 320, 480). In theory the view should be visible, as -80 for an origin Y coordinate would no bring the view outside the screen area, specially for a view with 320x480 pixels...
    It appears to be some sort of bug but I am out of ideas of what to put on XXXX to make the view visible and in landscape.
    Any ideas?

    Hi, Thanks for your answer.
    I see my original post was a little bit incomplete, so I will explain it better now. Sorry about that.
    have a landscape application. I am using a View Controller (I started the project on Xcode using View Based project). At the delegate, when program starts running, I have these lines...
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    and on the viewDidLoad method of ViewController, I do this
    // Rotate the view 90 degrees around its new center point.
    self.view.transform = CGAffineTransformRotate(self.view.transform, (-M_PI/2.0));
    // Repositions and resizes the view.
    CGRect contentRect = CGRectMake(0, 0, 480.0, 320.0);
    self.view.bounds = contentRect;
    So, now I have a landscape view, home button on the left and with the status bar hidden.
    At some point I am giving users a choice to choose one picture from the library or taking a photo. Then I use, obviously, UIImagePickerController. But as the UIImagePickerController is broken in landscape, I have to turn the view 90 degrees, back to what So, I do this...
    // position the view correctly, so the rotation will be correct
    self.view.center = CGPointMake(160,240);
    // rotate the view 90 degrees to put portrait
    self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0));
    // expand the fill to cover the whole portrait screen,
    // so, the UIImagePicker will fill the whole screen
    CGRect fullScreen = CGRectMake(0.0, 0.0, 320, 480);
    self.view.bounds = fullScreen;
    then I call the UIImagePicker....
    // Set up the image picker controller and add it to the view
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsImageEditing = YES;
    if ( ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) )
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [super presentModalViewController:picker animated:YES];
    everything is fine until now. THe picker is shown covering the whole screen and is in portrait.
    The problem start when I dismiss the picker. Which code should I use to dismiss the picker and have my application view back to what it was when I called the picker???
    thanks again!
    Message was edited by: Magno Urbano*

  • Hidden status bar while rotation not work

    Hi, Here is what I am doing:
    I have a view with status bar, nav bar and tool bar. User can tap the view to hidden all three bars. If tap again, all bars come back. All works fine.
    I found that if user hidden all bars, rotate the view to landscape mode, and then tap to bring the bars back, the status bar is overlap with nav bar.
    How can I fix it?
    thanks,
    fm

    You might have to mess with the frame of the nav bar after the rotate. Try something like this (assuming a variable named navBar):
    CGRect frame = navBar.frame;
    frame.origin.x = 20;
    navBar.frame = frame;

  • OpenGL Rotation Origin Problems

    Hi guys,
    I've had a browse around and can't seem to find any mention of this, i'm starting to make progress with learning OpenGL, but theres one thing thats totally throwing me off for the time being. Maybe someone will be kind enough to shed some light on this for me.
    Currently, i am simply rendering a textured rectangle to the screen. I was thumbing through tutorials and wanted to improve my rendering by adding in some rotation and possibly throw in some alpha blending when i came across this post http://www.iphonedevsdk.com/forum/iphone-sdk-development/2060-how-extend-texture 2d-opacity.html
    Huzzah i thought, as i happily modded my blitting method to include rotations and was presented with a slightly rotated object, but all was not as expected. For some reason (which i'm sure is totally obvious), the rectangle is rotated about the top left point, ie: 0.0, 0.0 which is really what i would expect, 0.0, 0.0 being the origin and all... but i want my object to be rotated around its center point, not the origin of the screen.
    I have set up my glOrthof and glViewport for landscape orientation as such:
    glViewport(0.0, 0.0, backingWidth, backingHeight);
    //other stuff here
    glOrthof(0.0, backingHeight, backingWidth, 0.0, -1.0, 1.0);
    This gives me a landscape orientation with the top left coords being 0.0, 0.0 and bottom right being 480.0, 320.0 which is my prefered coordinate system. As of such, this appears to be the main origin for all object rotations, which isn't really what i want. Is there any way i can translate an objects origin to rotate around its center point?
    for example, if i were to render the rect:
    my_rect = CGRectMake(backingWidth / 4, backingHeight / 4, backingWidth / 2, backingHeight / 2);
    a small rect half the width and height of the device would be presented directly in the center of the screen. Any rotations made to this however would be about the origin of 0.0, 0.0 of the screen and not the object itself. Is there any way to fix this so that the object would rotate around its center piont, in this example being the center of the screen?
    I dont mind changing the coordinate system if needs be, but i would still prefer to use the current 0.0, 0.0, 480.0, 320.0 landscape orientation as opposed to -1.0, 1.0, 1.0, -1.0 unless of course it would be a feasible endeavour to write a utility function to convert between the two coordinate systems when rendering?
    It seems that rotations must be made around the origin of the screen/device (0.0, 0.0) but surely that can't be the case as not every object/model rendered is required to rotate around the origin, but rather its own origin, if that makes sense?
    Is there a way to set the rotation origin, or translate the object to the screen origin, rotate and back again?
    Using the coordinate system 0.0, 0.0, 480.0, 320.0 for landscape orientation works perfectly, but obviously this issue with rotating objects around the origin is completely holding up any progress i can make.
    Please, if anyone knows of a method, or any tutorials that can outline what must be done, i would be very grateful for any help you guys can throw my way
    Just for completeness, the code i'm using for rotation is:
    glRotate(rotation, 0.0, 0.0, 1.0);
    Simple as it may seem, that one single line has caused me a weekend of headaches and very little progress. I'm positive there must be a way to fix this, can anyone point me in the right direction please?
    Any help would be greatly appreciated, thanks for reading

    Sorry to bump the post, but this is really starting to grind my gears. If anyone can provide a push in the right direction, i really, really would appreciate it
    I'm simply modding the Texture2D class from Apple's CrashLanding app to suit my needs but have hit this one stumbling block.
    The code i currently have is taken from Texture2D and modifed slightly, as follows:
    - (void)drawInRect:(CGRect)rect withRotation:(GLfloat)rotation
    GLfloat coords[] = {
    0.0, _maxT,
    _maxS, _maxT,
    0.0, 0.0,
    _maxS, 0.0
    GLfloar vertices[] = {
    rect.origin.x, rect.origin.y, 0.0,
    rect.origin.x + rect.size.width, rect.origin.y, 0.0,
    rect.origin.x, rect.origin.y + rect.size.height, 0.0,
    rect.origin.x + rect.size.width, rect.origin.y + rect.size.height, 0.0
    glPushMatrix();
    //this line is my assumed fix, but needs refining
    glTranslate(0.0, 0.0, 0.0);
    //rotate
    glRotate(rotation. 0.0, 0.0, 1.0);
    glBindTexture(GL_TEXTURE_2D, _name);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, coords);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glPopMatrix();
    The above code renders my rect properly with the right dimensions, at the right coordinates.
    The problem im having is that any rotations are made around the top left corner of the rect, which is the top left corner of the screen. I've set my viewport and glOrtho to present in landscape orientation which works fine, but obviosuly the rotations aren't what i desire.
    Surely there must be a way to "move" the origin about which the texture is rotated, ideally to the center of the texture itself. However, no matter what params i pass to glTranslatef(); it always rotates around the top left point of the rect itself.
    Please, please, can anyone help with this as it is really starting to drive me mad. Any help would be fantastic, a tutorial, a few lines of code or improvement upon what i posted above. Anything will do, i really want to get this solved so i can move on with things.
    Thanks for taking the time to read, i look forward to any replies

  • IPad status bar covers up my app's top  UIViews; okay after rotation

    I wrote an iPad app. When it is first started up (in iPhone simulator, or on real iPad) all the UIViews at the top of my window are partially covered-up by the iPads time/battery status bar.
    After I rotate the iPad (simulator or real one) the problem goes away: my UIViews appear shifted down, so they are under (below) the status bar. In other words, after I do the first rotation, the iPad knows to push my window downwards about 20 pixels to make room for the status bar. But before the first rotation (simulator or hardware) the iPad is not shifting my UIViews downward.
    Question: What can I do in software (during the startup logic) to get the iPad to push my window down to make room for the status bar?
    I think the iPad should do it automatically for me, but since it is not, I'm willing to take some action in the software to get it to happen. Any thoughts? NOTE: When I create all my UIViews, I'm using a coordinate of (0,0) for my upper left corner, which is correct, and after the first rotation everything works great. Also: I have auto-rotation enabled, so my app is always rotating to keep its display "up" so users can view it in all 4 rotations.

    Hi David -
    David Restler wrote:
    Question: What can I do in software (during the startup logic) to get the iPad to push my window down to make room for the status bar?
    If you're creating the view in your code, you're explicitly setting the view frame. The controller then assumes you know what you're doing and doesn't make any adjustment for the status bar (or any other bars that may be above or below the content area).
    In other words, when you explicitly set the frame in loadView, you're buying sole responsibility for the starting dimensions. In the case of an iPad with only the status bar, you need to drop the y-origin down 20, and shorten the height by 20:
    - (void)loadView {
    CGRect frame = CGRectMake(0, 20, 768, 1004);
    UIView *v = [[UIView alloc] initWithFrame:frame];
    self.view = v;
    [v release];
    NSLog(@"%s: self.view=%@ self.view.frame=%@",
    _func_, self.view, NSStringFromCGRect(self.view.frame));
    Btw, if you ever open your IB, try adding and subtracting the various simulated bars while watching the dimensions of the view in the Size Inspector. If the view is the main content view (i.e. connected to the 'view' outlet of File's Owner), you should see the y-origin and size adjust for each combination of bars. In fact, those dimensions will probably be grayed out, since IB doesn't trust us with such critical numbers. The point is, that when a view is loaded from a nib built with the correct simulated bars, the adjustment for the bars has already been saved in that file.
    I think the iPad should do it automatically for me
    If you want to see what the controller does by default (i.e. no nib and no frame defined in loadView), try this code:
    // MyAppDelegate.m
    #import "MyAppDelegate.h"
    #import "MyViewController.h"
    @implementation MyAppDelegate
    @synthesize window, viewController;
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    MyViewController *vc = [[MyViewController alloc] initWithNibName:nil bundle:nil];
    vc.view.backgroundColor = [UIColor grayColor];
    self.viewController = vc;
    [vc release];
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
    NSLog(@"%s: viewController.view.frame=%@",
    _func_, NSStringFromCGRect(viewController.view.frame));
    - (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
    @end
    // MyViewController.m
    #import "MyViewController.h"
    @implementation MyViewController
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
    [super viewDidLoad];
    @end
    When no nib name is specified, and the view loader can't find a nib that matches the owner's class name, and loadView isn't overridden, the view controller creates a default view (see no. 3 under "The steps that occur during the load cycle are as follows:" in [Understanding the View Management Cycle|http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGf oriPhoneOS/BasicViewControllers/BasicViewControllers.html#//apple_ref/doc/uid/TP 40007457-CH101-SW19] in the View Controller Programming Guide for iOS). If you run the above example code, you should see the frame of the default view takes all bars into account.
    ... I'm using a coordinate of (0,0) for my upper left corner, which is correct
    As explained above, it's not correct if there are any upper bars
    and after the first rotation everything works great.
    Yes, all bets are off after an auto-rotation. The system recalculates the content view frame in that case (though that math doesn't always come out the way you want).
    Hope that helps to unscramble things a little!
    - Ray

  • My iPod touch is stuck in landscape view.  Even when held vertically if I open facebook or safari is rotates to landscape.  Have tried turning on and off, same results. Any ideas to fix?

    My iPod touch is stuck in landscape view.  Even when held vertically if I open facebook or safari is rotates to landscape.  Have tried turning on and off, same results. Any ideas to fix?

    Try switching it back from landscape to vertical. Or, go to settings and see if you have any special setting turned on that enable only landscape view. Also, try hooking it up to your computer and charging it to see what happens.

  • I use preview's annotate feature to take notes by making text boxes in a PDF file. When I open the notes up again to review, all the text boxes have been rotated 90 degrees. Is there any way to prevent this from happening?

    If I click the boxes twice they rotate back but this is very annoying and time consuming.

    Just checking...still no fix for this? I upgraded to OSX 10.8.4 recently and started using Preview to annotate lecture notes, only to find text boxes rotated later on. Appears to be okay if I go back and click on all text boxes and save again.
    Any new updates on this topic re: why this is occuring and how to permanently fix it?

  • X230t and Windows 8 - tablet rotate and control buttons don't work

    I am the proud owner of a new x230 tablet and I couldn't resist the tempation to load up Windows 8 on it.  Overall I have found the operating system to work fairly well on the system as installed "out of the box"; however, I have noticed that when the computer is put in tablet mode the screen doesn't rotate, even if the rotate hardware button is pressed.  Has anyone else encountered this and if so is there a solution other then waiting for the official release of the operating system and windows 8 certified drivers.
    Thanks

    This is for win7 but should also work in win8 because it is a simple configuration thing:
    http://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/how-torotate-screen-in-windows-7-...
    similar:
    http://answers.yahoo.com/question/index?qid=20070808054356AAufqKb
    Using x230t (i5-3320M, 8GB RAM, 256GB SSD, 80GB mSata-SSD) and loving it!
    "I may not own the world but I own my mind and therefore the world is at my feets." (me)

  • Need "Rotate" Function in Photo Gallery

    All of my screen grabs end up 90 degrees rotated in PhotoGallery. There is no rotate function in Photo Gallery so to deal with these images I first open them in Adobe Editor on iPad and rotate them then save them to PhotoGallery.
    Is there a better way to do this?

    To the example that you have linked to above, make the following additions
      <div id="arch-container" style="position:relative;">
        <div id="arch-img" style="position:absolute; top: 170px;"><img src="images/arch-img.png" alt="arch_img" width="959" height="195" /></div>
      </div>
    I have used inline styles to make it easy on myself, but in reality you would put the style rules in the corresponding element selector in the CSS. Also, you would readjust the values to suit.
    Also, it is worth mentioning that placing a width and height on your image as you have done, should really be done using CSS.
    Added:
    As a side note, I have gotten into the habit of using classes for all of my style rules. I came to the conclusion that this is the way to go when trying to analyse a problem within my web page. ID's are unique per document and as such are used when manipulating the DOM using JavaScript. Now when I see an ID in one of my documents, I know that it is not a styling matter as in CSS, but a problem within my script.
    Take the above note as a thought, because there is a ongoing debate about this.
    Message was edited by: Altruistic Gramps

  • IPhoto rotates images in slideshow even though the thumbnail for that images has the correct orientation.

    This problem seems bizarre to me considering iPhoto 11 has worked with out a hitch since I upgraded from 09 ages ago.  The photos in my album suddenly changed orientation from landscape to portrait and vice versa and sometimes upside down.  I first notice this problem after I tried to click and drag a large number of photos directly from iPhoto to Finder.  I did a Command-A to highlight all the photos from my album and tried to drag them to a folder in Finder.  There are 34,000 photo in this album but only half were copied, (I guess 34,000 items is too much for Lion to copy all at once).  I tried fixing this orientation problem by highlighting all affected photos and selecting "Revert to Original" which fixed the orientation of the thumbnails.  But when you double click on a thumbnail to view the pictures or view the album in a slideshow, some of the pictures still have the incorrect orientation but most were corrected.  Also if I double click on an affected photos to edit it with iPhoto image editor the image suddenly orientates itself correctly.  Then as soon as I close the image editor and view the photo or start a slide show it's displayed with the incorrect orientation again.   How is that possible that all my thumbnails are orientated properly but when I view the photo it's rotated sideways or sometimes rotated upside down?    Any help or insight to my problem would be much appreciated.

    Revereting to original will not fix the problem.  When you invoke that menu option iPhoto will read the file again, see the tag that tells it to rotate the file and will rerotate it. 
    The most reliable way to fix this is to rotate those file before they are imported into iPhoto. Upload from the camera to a folder on the Desktop, rotate those that need rotating, rename if desired and import.  I use Xee for that because it can rotate the file losslessly.
    OT

  • Rotate to fit / photoshop image processor

    Anyone know what happened to the Rotate to Fit feature in bridge/tools/photoshop/image processor? I have to make several web photo galleries and this most important feature seems to be missing with CS4.

    To clarify - older photoshop (or bridge) programs, you could put in the dimensions you wanted and check a checkbox that said something like "rotate to fit". So if I entered 400x600px, then photoshop would make Portrait images 600 tall x 400 wide, and Landscape image 600 wide by 400 tall.
    Photoshop CS4 doesn't have that option so I have to go through all of my images, select all the landscape images, put in 600 wide x 400 tall, and run the script. Then gotta Go Back... select all of the Portrait images.. and run the script again but this time for 600 tall x 400 wide. Such a pain - gotta be a better way just haven't found it yet! help!

  • Why my iphone 5s is not rotating

    my iphone 5s is not rotating and parallax wallpaper not work.
    first I reset and nothing then reboot and again not work and Reduce Motion and again nothing.
    please HELP ME

    Use the 4Rs basic troubleshooting steps:
    Restart:
    1. Press and hold the Sleep/Wake button until the red "slide to power off" slider appears, and then slide the slider.
    2. Press and hold the Sleep/Wake button until the Apple logo appears.
    Reset: Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Note: You will not lose any data
    Restore from backup
    Restore as new
    http://support.apple.com/kb/HT1414

  • Problem with some synced photos to my iphone rotating incorrectly

    I recently synced a folder of photos in My Pictures to my iPhone 4 via iTunes.  68 picture...21 were taken in a portrait rotation, the rest were landscape.  I had no tropuble with the landscape photos.  But, after the sync, 5 of the 21 portrait photos had the wrong rotation.  From my basic troubleshoot...they are not all rotated incorrectly in the same direction and I confirmed that they all have a similar resolution as at least one of the correctly oriented portrait photos from the same sync.  Editing and saving the picture directly on the iPhone is not an option because I am only given the option to save an edited photo to the Camera Roll album.  It is extremely frustrating.  Why does this process ignore the native orientation of only some of the synced photos?  I'd be less confused if it mess up all of the portrait photos.  I would very much appreciate any advice to fix this seemingly arbitrary malfunction.  Thank you.

    I'm having a problem where when I import my iPhone photos into Picasa, photos are rotated incorrectly (even when viewed in Finder). Landscape photos are upside down, portrait photos aren't rotated to portrait orientation. I suspect this has someting to do with the iPhone saving photos without rotating them based on iPhone orientation and instead adding EXIF data to indicate the orientation based on something I read online, but I don't really know. When viewing info for a portrait photo in Preview, it indicates Y resolution is less than X resolution (which is what it should be for landscape photos only), and on the TIFF tab says Orientation 1 (Normal).
    So my question is, why is it not being rotated properly in the iPhone for use on other devices? How can I fix this?
    It should be noted that important photos with iPhoto or Image Capture makes it display properly in Preview and Finder with updated Orientation information, but still not in Firefox (so... good for some software on your Mac but even still not if you intend to send the picture to anyone... MAJOR BUG ).
    BTW using iPhone 4s with latest version of iOS 5.1.1, Mac OS X Mountain Lion.
    PS VIdeo orientation is perfect.

  • A better way to rotate a shape

    I need a way to easily rotate several Ellipse2D objects. The approach I'm using is not working because it's rotating the entire coordinate system in my Canvas object:
    public void paint(Graphics g) {     
    Graphics2D g2 = (Graphics2D) g;          
    Ellipse2D.Double e = new Ellipse2D.Double(220.0, 75.0, 47.0, 30.0);
    AffineTransform rotate45 =
    AffineTransform.getRotateInstance(Math.toRadians(161.5),
    220.0, 75.0);
    g2.setTransform(rotate45);
    g2.draw(e);
    } // end paint
    Is there something better to use other than AffineTransform that will allow me to rotate just the shape itself?
    thanks,
    Eric

    You can still use AffineTransform. There is a method called createTransformedShape and it does what you want.
    http://java.sun.com/j2se/1.4.1/docs/api/java/awt/geom/AffineTransform.html#createTransformedShape(java.awt.Shape)
    Ellipse2D e = ...
    AffineTransform rotate45 = ...
    e = (Ellipse2D) rotate45.createTransformedShape(e);
    ...

  • Need to find out how to lock a point in a path that will not allow the rest of the path to rotate or move around it

    Hello,
    I am having some trouble with using shape layers and paths to create a solid, flat 'hair' effect in a cartoon animation.
    I have used a semicircle shape layer as the hair on the head itself and then a path with a stroke of the same width as the semi circle to be the long part of the hair.
    Unfortunately when I move/rotate the bottom point in the path it causes gaps to appear further up where the stroke is rotating around the point at which the stroke is supposed to "connect" to the semi circle.
    I have included a couple of screenshots of me rotating the hair opposite ways so you can see.
    - imgur: the simple image sharer
    - imgur: the simple image sharer
    I need to find out if there is a way to lock the top point in place where it joins the semi circle blond hair which will stop this part from moving at all, even rotating around the point.
    But the bottom needs to move freely and obviously the part between the two points will move fairly naturally.
    If you can imagine how a girl with long hair has her hair attached to her head, it does not move at all, but the bottom moves freely. It needs to be like this.
    If you can provide any assistance it would be greatly appreciated.
    Thanks!

    That is perfect thank you so much!
    Can't believe I didn't think of that but you da real MVP!

Maybe you are looking for