typhoon icon indicating copy to clipboard operation
typhoon copied to clipboard

Interface orientation iPhone/iPad in injected view controllers

Open jcmartinac opened this issue 9 years ago • 4 comments

Hi, I have a problem injecting my initial view controller (a navigation with a view controller as root) when I run it in landscape orientation.

The app should run portrait in iPhone and landscape in iPad, but only iPhone render well. In iPad starts rotated, and looks like size classes aren't working, because I can see a black background. Link to image:

https://www.dropbox.com/s/tqqca444ooe9gkj/Captura%20de%20pantalla%202016-03-07%20a%20las%2010.49.37.png?dl=0

And this is mi code to inject the initial viewcontroller:

  • (UIWindow *) mainWindow { return [TyphoonDefinition withClass:[UIWindow class] configuration:^(TyphoonDefinition *definition) { [definition useInitializer:@selector(initWithFrame:) parameters:^(TyphoonMethod *initializer) { [initializer injectParameterWith:[NSValue valueWithCGRect:[[UIScreen mainScreen] bounds]]]; }]; [definition injectProperty:@selector(rootViewController) with:[self rootViewController]]; }]; }
  • (UINavigationController *) rootViewController { return [TyphoonDefinition withClass:[UINavigationController class] configuration:^(TyphoonDefinition *definition) { [definition useInitializer:@selector(initWithRootViewController:) parameters:^(TyphoonMethod *initializer) { [initializer injectParameterWith:[self viewController]]; }]; }]; }
  • (ViewController *) viewController { return [TyphoonDefinition withClass:[ViewController class] configuration:^(TyphoonDefinition *definition) { [definition injectProperty:@selector(assembly) with:self]; }]; }

Looking into documentation and forums, I have not found any help. Am I forgetting something?

jcmartinac avatar Mar 07 '16 10:03 jcmartinac

It looks that the problem comes from init the main window frame in the assembly, because it doesn't set it properly. (In simulator doesn't work at all) When I set the main window frame in the appDelegate didFinishLaunchingWithOptions like this: self.window.frame = [UIScreen mainScreen].bounds; it works fine, but with another problem: the device rotation doesn't work... Any idea?

jcmartinac avatar Mar 07 '16 12:03 jcmartinac

Hm.. Typhoon just instantiates ViewControllers and Windows for you. It's similar like if you create it on your own somewhere in another place. So it's not Typhoon problem, but something with UIKit configuration. ( UIKit is magic box - results are often unknown)

For your case, I would recommend using UIStoryboard as entry point, since it's standard approach now in iOS. Typhoon works with UIStoryboard very well

alexgarbarev avatar Mar 15 '16 14:03 alexgarbarev

I have the same issue, and if create window at didFinishLaunchingWithOptions

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.rootViewController;

all works as expected.

such code do not work as expected. The same black line and no rotations

- (UIWindow *)mainWindow {
    return [TyphoonDefinition withClass:[UIWindow class] configuration:^(TyphoonDefinition * definition) {
        [definition useInitializer:@selector(initWithFrame:) parameters:^(TyphoonMethod * initializer) {
            [initializer injectParameterWith:[NSValue valueWithCGRect:[[UIScreen mainScreen] bounds]]];
        }];
        [definition injectProperty:@selector(rootViewController) with:[self rootViewController]];
    }];
}

niphlhell avatar Jun 23 '16 23:06 niphlhell

The Typhoon sample app exhibited the same issue, so the window was created with code inside the app delegate: https://github.com/appsquickly/Typhoon-Swift-Example

Interestingly, this problem does not occur with the Objective-C version.

jasperblues avatar Jun 23 '16 23:06 jasperblues