ibm123
ibm123

Reputation: 1254

Rotation for view when viewcontroller locked to portrait in ios6/ios7

I got a view controller which is something like facebook's status feed vc which is looked to portrait. when tapping an image the vc create a custom 'full image view' and add it to it's super view. while the viewcontroller is locked to portrait I still want to let the user to be able rotate the device to see the image in landscape mode as well.. when closing the 'full image view' the custom view remove itself from the superview, in that moment I want to lock the vc view to portrait.

Bottom line, I want the vc to be locked to portrait but let the user the option to see the full image in both orientation.

Upvotes: 0

Views: 81

Answers (2)

Prince Agrawal
Prince Agrawal

Reputation: 3607

When we are talking about orientation, they are 2 things that come into the picture:

  1. Device Orientation
  2. Interface Orientation

As its clear by the name only, Device orientation tells, in which orientation device is, and Interface orientation says in which orientation your app is presenting its interface.

"I want the VC to be locked to portrait but let the user the option to see the full image in both orientation."

By this, its clear that you don't want to change interface of your App. What you want is to rotate the image, when device orientation is changes.

For that, First thing you should do is, have a look at this method beginGeneratingDeviceOrientationNotifications

Write this to get notified each time when Device orientation is changed [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

Now, in the viewController where you are showing the images, write this

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];

In deviceOrientationDidChange method, rotate the image as per device orientation Let me know if more info needed..

Upvotes: 1

Mykod
Mykod

Reputation: 687

when you present the image :

if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
UIImageView.transform = CGAffineTransformMakeRotation(M_PI + M_PI_2);     
}

This should work, but I did not test it!

Upvotes: 0

Related Questions