iOS和corona view景观问题
我正在尝试使用corona卡将corona(游戏平台)与iOS项目集成。以下是我努力实现的目标:iOS和corona view景观问题,ios,objective-c,iphone,coronasdk,Ios,Objective C,Iphone,Coronasdk,我正在尝试使用corona卡将corona(游戏平台)与iOS项目集成。以下是我努力实现的目标: 以编程方式从AppDelegate.m加载corona视图控制器(ViewController.m/ViewController.h) corona view控制器的强制横向模式 代码如下: AppDelegate.m ViewController*ViewController=[[ViewController alloc]init]; self.window.rootViewControll
- 以编程方式从AppDelegate.m加载corona视图控制器(ViewController.m/ViewController.h)
- corona view控制器的强制横向模式
ViewController*ViewController=[[ViewController alloc]init];
self.window.rootViewController=viewController;
[self.window makeKeyAndVisible]
发生这种情况是因为当您从纵向模式
转到横向模式
时,屏幕的宽度和高度会发生变化。所以,coronaView.frame.size.width!=[UIScreen mainScreen].bounds.size.width
从纵向
切换到横向
要解决这些问题,最好使用AutoLayout
在viewdlayoutsubviews
中设置帧或在ViewController
s中设置帧
-(void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CoronaView *coronaView = (CoronaView *)_coronaController.view;
coronaView.frame = self.view.frame;
}
或
请检查我的答案,并让我知道它是否解决了您的问题。我尝试了您的方法,图像看起来很有弹性。以下是屏幕截图:您的
图像是否在UIImageView
内?如果是这样,请设置imageView.contentMode=uiviewContentModeScaleSpectFit
图像实际上是从计算机提供的,因为内容模式设置为UIViewContentModeScaleToFill
。所以,如果我们不能控制它,我们就无能为力。不带整个屏幕的问题解决了吗?
- (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]];
}