ios - Running code in app regardless of view -
i want app trigger action when iphone's orientation changes, regardless of user in app.
i'm using
if (([[uidevice currentdevice] orientation] == uideviceorientationlandscapeleft) || ([[uidevice currentdevice] orientation] == uideviceorientationlandscaperight)) { }
to check orientation of device.
where put code run if orientation changes?
in app delegate, register uideviceorientationdidchangenotification
notification.
then in selector notification, can perform if
check.
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(orientationchange) name: uideviceorientationdidchangenotification object:nil]; // else had in method } - (void)orientationchange { if (([[uidevice currentdevice] orientation] == uideviceorientationlandscapeleft) || ([[uidevice currentdevice] orientation] == uideviceorientationlandscaperight)) { } }
Comments
Post a Comment