How to change the orientation of the device depending on the on and off button?

I need to change the orientation of the application while the application is running. My process is that if I turn on the switch, the application must change its orientation (ie) (i) if the application works in landscape orientation, and then if I return "ON" to the switch button, then the device orientation should automatically change in portrait mode. (ii) if the application is in Portrait mode, if I turn off the switch, then the orientation of the device should automatically change to landscape mode ... I tried something, but it is not hushed up for me .. can anyone give some solution? for this..

 - (IBAction)PortraitSwitchPressed:(UISwitch *)sender
   {
     if (sender.isOn)
     {
        UIInterfaceOrientationMaskPortrait;
        [[UIDevice currentDevice]setOrientation:UIInterfaceOrientationPortrait]; // no visible @interface for 'UIDevice' declares the selector setorientation
          [self.PortraitSwitch setOn:YES animated:YES];
      }
else
     {

       UIInterfaceOrientationMaskLandscape;
      [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationMaskLandscape];
         [self.PortraitSwitch setOn:NO animated:YES];
}}
+4
1

:

- (IBAction)PortraitSwitchPressed:(UISwitch *)sender
{
        if (sender.isOn)
        {
            NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
            [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
            [self.PortraitSwitch setOn:YES animated:YES];
        }
        else
        {

            NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];//or UIInterfaceOrientationLandscapeRight
            [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
            [self.PortraitSwitch setOn:NO animated:YES];
        }
}

UIInterfaceOrientation .

0

All Articles