3

我正在实现一个通用应用程序。我在 init 方法中实现了一个“UIView”,如下所示:

[self setWantsFullScreenLayout:YES];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
    Menu = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
    [Menu setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Fond_Menu.png"]]];
}
else
{
   Menu = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 768, 1024)];
   [Menu setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Fond_Menu_Ipad.png"]]];
}
[self.view addSubview:Menu];
[Menu release];

但是当我添加一个“UIButton”时,它可以在 Iphone 模拟器上运行,而不是在 Ipad 上运行。

请参阅,在“ViewDidLoad”方法中:

Jouer = [UIButton buttonWithType:UIButtonTypeCustom];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
    [Jouer setFrame:CGRectMake(82.5, 240, 155, 35)];
    [Jouer setImage:[UIImage imageNamed:NSLocalizedString(@"Bouton_Jouer", @"")] forState:UIControlStateNormal];
    [Jouer setImage:[UIImage imageNamed:NSLocalizedString(@"Bouton_Jouer_HIGH", @"")] forState:UIControlStateHighlighted];
}
else
{
    [Jouer setFrame:CGRectMake(214, 505, 340, 77)];
    [Jouer setImage:[UIImage imageNamed:NSLocalizedString(@"Bouton_Jouer_Ipad", @"")] forState:UIControlStateNormal];
    [Jouer setImage:[UIImage imageNamed:NSLocalizedString(@"Bouton_Jouer_HIGH_Ipad", @"")] forState:UIControlStateHighlighted];
}
[Jouer addTarget:self action:@selector(MyMethod)forControlEvents:UIControlEventTouchUpInside];
[Menu addSubview:Jouer];

请问如何解决?

4

3 回答 3

3

确保您的项目配置为构建“通用”应用程序。在 iPad 上运行的 iPhone 应用程序仍会将其 UI 习语识别为“iPhone”。

于 2013-09-13T18:06:35.897 回答
0

固定的 !

我忘记在代表中区分 iPhone 和 Ipad,所以主窗口是 iPhone 格式 =)

于 2013-09-13T21:51:16.470 回答
0

检查您在按钮上设置的图像 - 如果其中一个 iPad 为 nil,这可能会导致您的按钮无法正确显示。如果不是,请检查您的按钮操作实现。

于 2013-09-13T18:11:18.580 回答