2017-02-20 12 views
0

コロナカードを使用してiOSプロジェクトにコロナ(ゲームプラットフォーム)を統合しようとしています。以下は、私が達成しようとしていているもの:以下iOSとコロナビューランドスケープの問題

    AppDelegate.mから
  • プログラムのロードコロナ・ビュー・コントローラ(ViewController.m/ViewController.h)
  • コロナビューコントローラの
  • 強制ランドスケープモード

コードです:

AppDelegate.mは

ViewController *viewController = [[ViewController alloc] init]; 
 
self.window.rootViewController = viewController; 
 
[self.window makeKeyAndVisible];

ViewController.m

@interface ViewController() 
 
    @property (nonatomic, strong) CoronaViewController *coronaController; 
 
@end 
 

 
- (void)viewDidAppear:(BOOL)animated { 
 
    _coronaController = [[CoronaViewController alloc] init]; 
 
    [self addChildViewController:_coronaController]; 
 
    
 
    CoronaView *coronaView = (CoronaView *)_coronaController.view; 
 
    coronaView.frame = self.view.frame; 
 
    
 
    [self.view addSubview:coronaView]; 
 
    [coronaView run]; 
 
}

ここにそれがどのように見えるかのスクリーンショットです:

  • ポートレートモード:image

  • 風景モード:image

問題は、私が風景に行くとき、画像が画面全体を取るべきではなく、それだけで部分画像を示すことです。

* UPDATE * 私は、次の手順を実行して、この作業を取得することができました:

CGRect appFrame = [UIScreen mainScreen].bounds; 
 
_coronaView.frame = CGRectMake(0, -162, appFrame.size.height, appFrame.size.width); 
 
[self.view addSubview:_coronaView]; 
 
[_coronaView setNeedsLayout];

を私は私のyを設定しなければならなかった理由しかし、私はわかりません - 162。お役に立てれば。

+0

してください私の答えをチェックし、あなたの問題を解決するかどうか教えてください – KrishnaCA

+0

私はあなたのアプローチを試み、イメージが伸びているように見えます。ここにスクリーンショットがあります:http://imgur.com/a/X3IgI –

+0

は 'UIImageView'の中の'画像 'ですか?もしそうなら、 'imageViewを設定します。contentMode = UIViewContentModeScaleAspectFit' – KrishnaCA

答えて

0

Landscape modeからPortrait modeに移動すると、画面の幅と高さが変化するためです。だから、これらの問題を解決するにはLandscape

PortraitからずれたときにcoronaView.frame.size.width != [UIScreen mainScreen].bounds.size.widthは、それがフレームを設定したりViewController秒でviewDidLayoutSubviewsにフレームを設定するためのAutoLayoutを使用することをお勧めします、

-(void)viewDidLayoutSubviews { 
    [super viewDidLayoutSubviews]; 
    CoronaView *coronaView = (CoronaView *)_coronaController.view; 
    coronaView.frame = self.view.frame; 
} 

または

- (void)viewDidAppear:(BOOL)animated { 
    _coronaController = [[CoronaViewController alloc] init]; 
    [self addChildViewController:_coronaController]; 

    CoronaView *coronaView = (CoronaView *)_coronaController.view; 
    [self.view addSubview:coronaView]; 

    NSLayoutConstraint *constraint1 = [NSLayoutConstraint constraintWithItem:coronaView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0]; 
    NSLayoutConstraint *constraint2 = [NSLayoutConstraint constraintWithItem:coronaView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0]; 
    NSLayoutConstraint *constraint3 = [NSLayoutConstraint constraintWithItem:coronaView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0]; 
    NSLayoutConstraint *constraint4 = [NSLayoutConstraint constraintWithItem:coronaView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]; 
    [self.view addConstraints:@[constraint1, constraint2, constraint3, constraint4]]; 
} 
関連する問題