2

私のアプリは 2 番目の画面 (外部モニター) を駆動しますが、回転に関して「奇妙な」ことがいくつか見られます (iOS7 では起こらないこと)

アプリを横向きで起動し (そして 2 番目の画面を接続)、ホーム ボタンを押してアプリをバックグラウンドにし、アプリを再度開くと、2 番目の画面 (モニターに接続されている) が 90 度回転し、画面半分。その後の回転量はこれを修正しません。

これはバグであると確信していますが、それ以外の場合は喜んでお知らせします。以下は、単純なシングル ビュー アプリケーションでそれを再現するためのコードです。

ありがとう

@interface AppDelegate ()

@property (nonatomic, strong) UIWindow* externalWindow;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];

    UIScreen* externalScreen = ([UIScreen screens].count > 1 ? [[UIScreen screens] objectAtIndex:1] : nil);
    if (externalScreen)
    {
        [self setupExternalScreen:externalScreen];
    }

    return YES;
}

- (void) screenDidConnect:(NSNotification *)aNotification
{
    UIScreen* externalScreen = (UIScreen*)aNotification.object;
    [self setupExternalScreen:externalScreen];
}

- (void)setupExternalScreen:(UIScreen*)externalScreen
{
    externalScreen.currentMode = externalScreen.preferredMode;

    self.externalWindow = [[UIWindow alloc] initWithFrame:externalScreen.bounds];
    self.externalWindow.screen = externalScreen;
    self.externalWindow.clipsToBounds = YES;
    self.externalWindow.hidden = NO;
    [self.externalWindow makeKeyAndVisible];

    UIViewController* externalViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    externalViewController.view.backgroundColor = [UIColor redColor];
    self.externalWindow.rootViewController = externalViewController;
}
@end
4

3 に答える 3

5

OK - 修正しました。

設定するのではなく、

self.externalWindow.rootViewController = externalViewController;

代わりに、ビューをウィンドウのサブビューとして追加するだけです (ビュー コントローラー オブジェクトへの参照を保持することを忘れないでください)。

self.externalViewController.view.frame = self.externalWindow.frame;
[self.externalWindow addSubview:self.externalViewController.view];

View Controllerのものが混乱していたと思います.....

于 2014-10-16T17:05:25.650 に答える
0

UIWindow を変換して解決するだけです

CGRect frame = screen.bounds;

if (!self.secondWindow) {
    UIWindow *extWindow = [[UIWindow alloc] initWithFrame:frame];
    self.secondWindow = extWindow;
}

if ([[[UIDevice currentDevice] systemVersion] integerValue] == 8) {
    CGFloat magicAmount = (frame.size.width - frame.size.height) / 2;
    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
        float rotation = M_PI_2;
        self.secondWindow.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rotation), magicAmount, magicAmount);
    }
    else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
        float rotation = -M_PI_2;
        self.secondWindow.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rotation), -magicAmount, -magicAmount);
    }
}
于 2015-08-28T07:56:30.337 に答える