force landscape ios 7

Here is how I forced one of my views to be Landscape using NavigationViewController: Implemented this answer: https://stackoverflow.com/a/12662433/2394787 Imported message in the View controller: objc/message.h Added this line of code in the viewDidLoad method: objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft); Hope it helps someone.

presenting ViewController with NavigationViewController swift

Calling presentViewController presents the view controller modally, outside the existing navigation stack; it is not contained by your UINavigationController or any other. If you want your new view controller to have a navigation bar, you have two main options: Option 1. Push the new view controller onto your existing navigation stack, rather than presenting it … Read more

iOS Nested View Controllers view inside UIViewController’s view?

No, this is generally good design, it helps keep your view controllers concise. However you should be using the view controller containment pattern, take a look at the following documentation. Implementing a Container View Controller This is incredibly simple to setup using Interface Builder with Storyboards as well, take a look at the Container View … Read more

Programmatically switching between tabs within Swift

If your window rootViewController is UITabbarController(which is in most cases) then you can access tabbar in didFinishLaunchingWithOptions in the AppDelegate file. func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool { // Override point for customization after application launch. if let tabBarController = self.window!.rootViewController as? UITabBarController { tabBarController.selectedIndex = 1 } return true } This will … Read more

In iOS, how to drag down to dismiss a modal?

I just created a tutorial for interactively dragging down a modal to dismiss it. http://www.thorntech.com/2016/02/ios-tutorial-close-modal-dragging/ I found this topic to be confusing at first, so the tutorial builds this out step-by-step. If you just want to run the code yourself, this is the repo: https://github.com/ThornTechPublic/InteractiveModal This is the approach I used: View Controller You override … Read more

Swift programmatically navigate to another view controller/scene

Swift 5 The default modal presentation style is a card. This shows the previous view controller at the top and allows the user to swipe away the presented view controller. To retain the old style you need to modify the view controller you will be presenting like this: newViewController.modalPresentationStyle = .fullScreen This is the same … Read more

Only ONE VIEW landscape mode

Swift AppDelegate.swift internal var shouldRotate = false func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return shouldRotate ? .allButUpsideDown : .portrait } Your landscape view controller let appDelegate = UIApplication.shared.delegate as! AppDelegate appDelegate.shouldRotate = true // or false to disable rotation Objective-C AppDelegate.h @property (assign, nonatomic) BOOL shouldRotate; AppDelegate.m – (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow … Read more