ios - How to set device orientation only landscape? -
i'm writing simple app under macos
using xcode
. want app in landscape mode always. set landscape orientation in project properties. when add button window.subview
, button doesn't appear in landscape position.
i have appdelegate class. i've changed function: - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions
i've added:
self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; self.window.backgroundcolor = [uicolor purplecolor]; [self.window makekeyandvisible]; uibutton *button = [uibutton buttonwithtype:uibuttontyperoundedrect]; [button setbackgroundcolor:[uicolor whitecolor]]; [button setframe:cgrectmake([[uiscreen mainscreen] bounds].size.width/2 - 50, [[uiscreen mainscreen] bounds].size.height/2, 100, 100)]; [button settitle:@"button" forstate:uicontrolstatenormal]; [self.window addsubview:button];
update: added [self.window settransform:cgaffinetransformmakerotation(-m_pi/2)];
and got:
select target project , make sure have choose following landscape mode:
Comments
Post a Comment