1

I wanna make screen rotate by clicking a button. However, due to complex layout and I'm using sizeClass, I don't plan to achieve it by setting views' transform. So can I call system's method. If yes, and how?

elephant
  • 31
  • 4
  • Well you can override but then the user still has to turn the device and trigger it manually if you don't want to make to make it like super convoluted. – LinusGeffarth Jun 21 '15 at 06:54
  • @LinusG. I got it! So the best solution is to set views' transform? – elephant Jun 21 '15 at 07:17
  • @LinusG. I mean I wanna make a view (a lot of subviews in it) rotate like system's auto rotation. So the solution is only to set views' transform? – elephant Jun 21 '15 at 07:23
  • Sorry, I do not know what you mean with *views' transform* – LinusGeffarth Jun 21 '15 at 07:24
  • @LinusG. There's a view with a lot of subviews in it, and I want to make it rotate like system's auto rotation by touching a button. How to make the view and its subviews layout perfectly after the rotation? – elephant Jun 21 '15 at 07:32
  • Oh well you could either use auto layout or calculate positions on screen depending on its width. You could change the layout in the method that is called when the screen rotates. Something with an `NSNotification`. I forgot, sorry. – LinusGeffarth Jun 21 '15 at 07:35
  • @LinusG. I had used sizeClass with auto layout to layout views in IB, but I don't know how to trigger it. Because the rotation is not the real screen rotation just like a transform! – elephant Jun 21 '15 at 07:58
  • Oh so you want to "rotate" instead of actually rotating? So in fact, technically, it is still portrait but it looks like landscape? – LinusGeffarth Jun 21 '15 at 08:00
  • @LinusG. Yes! Please give me some suggestions – elephant Jun 21 '15 at 08:03
  • Thats actually a good idea. Well that's easy. In the button's selector method simply set the new locations. Oh and also you need to rotate the views like here: http://stackoverflow.com/a/21374041/3397217 – LinusGeffarth Jun 21 '15 at 08:07
  • That's why at beginning I wanna call system's method, if I can call it, it can trigger the auto layout in IB. – elephant Jun 21 '15 at 08:10

1 Answers1

0

Try this:

if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
{
     objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait );
}

However this is a private API.

Misha
  • 5,260
  • 6
  • 35
  • 63