Skip to content

Instantly share code, notes, and snippets.

func currentController() -> UIViewController? {
if self.pageViewController?.viewControllers?.count > 0 {
return self.pageViewController?.viewControllers![0]
}
return nil
}
func currentControllerIndex() -> Int {
let pageItemController = self.currentController()
if let controller = pageItemController as? PageItemController {
return controller.itemIndex
}
return -1
}
- (NSUInteger)currentControllerIndex
{
PageItemController *pageItemController = (PageItemController *) [self currentController];
if (pageItemController)
{
return pageItemController.itemIndex;
}
return -1;
@interface RadiosPreferences : NSObject
@property (nonatomic) BOOL airplaneMode;
- (void)synchronize;
@end
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([self.window.rootViewController.presentedViewController isKindOfClass:[SecondViewController class]])
{
return UIInterfaceOrientationMaskAll;
}
else return UIInterfaceOrientationMaskPortrait;
}
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
if self.window?.rootViewController?.presentedViewController is SecondViewController {
return UIInterfaceOrientationMask.All;
} else {
return UIInterfaceOrientationMask.Portrait;
}
@interface SecondViewController ()
@property (nonatomic) BOOL isPresented; // This property is very important
@end
@implementation SecondViewController
- (void)viewDidLoad
{
class SecondViewController: UIViewController {
var isPresented = true // This property is very important, set it to true initially
@IBAction
func dismiss() {
isPresented = false // Set this flag to NO before dismissing controller, so that correct orientation will be chosen for the bottom controller
self.presentingViewController!.dismissViewControllerAnimated(true, completion: nil);
}
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([self.window.rootViewController.presentedViewController isKindOfClass:[SecondViewController class]])
{
SecondViewController *secondController = (SecondViewController *) self.window.rootViewController.presentedViewController;
if (secondController.isPresented) // Check current controller state
{
return UIInterfaceOrientationMaskAll;
}
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
if self.window?.rootViewController?.presentedViewController is SecondViewController {
let secondController = self.window!.rootViewController!.presentedViewController as! SecondViewController
if secondController.isPresented { // Check current controller state
return UIInterfaceOrientationMask.All;
} else {
return UIInterfaceOrientationMask.Portrait;