代码适用于iPhone模拟器,但不适用于设备
问题描述:
我使用以下代码在iPad应用程序中的两个不同皮肤/主题之间切换。 该代码在模拟器中正常工作,但不在设备上。任何人都可以提出任何建议,为什么这可能会发生?代码适用于iPhone模拟器,但不适用于设备
if (skin == 1) {
UIImage* skinSelector = [UIImage imageNamed:@"button1.png"];
self.imgSkinSelector = [[UIImageView alloc] initWithImage:skinSelector];
self.imgSkinSelector.center = CGPointMake(88, 88);
self.imgSkinSelector.alpha = 0;
[self.landscape addSubview:self.imgSkinSelector];
}
else {
UIImage* skinSelector2 = [UIImage imageNamed:@"button2.png"];
self.imgSkinSelector = [[UIImageView alloc] initWithImage:skinSelector2];
self.imgSkinSelector.center = CGPointMake(74, 74);
[self.landscape addSubview:self.imgSkinSelector];
// self.skinSelector.hidden = 1;
}
答
试试这个:
首先,不要ALLOC你想改变你的主题,每次imgSkinSelector。分配/ init仅在viewDidLoad中/的loadView功能类似下面一次:
self.imgSkinSelector = [[UIImageView alloc] init];
在你的功能,你在哪里改变主题
然后,使用此代码:
if (skin == 1) {
[self.imgSkinSelector setImage:[UIImage imageNamed:@"button1.png"]];
self.imgSkinSelector.center = CGPointMake(88, 88);
self.imgSkinSelector.alpha = 0;
[self.landscape addSubview:self.imgSkinSelector];
} 其他{
[self.imgSkinSelector setImage:[UIImage imageNamed:@"button2.png"]];
self.imgSkinSelector.center = CGPointMake(74, 74);
[self.landscape addSubview:self.imgSkinSelector];
}
希望这适用于你。
答
我曾经遇到过一个问题,那就是模拟器正确地选取了资源(图片)而不是设备(iPhone)。
至少在我的情况下,原来是图像名称的情况。确保图像的名称是完全写在代码(button.png/Button.png等)
只是一个猜测...
答
可以b一些问题与您的图像它显示在模拟器罚款不是在设备中...只是4尝试使用另一个图像来代替。 谢谢
什么不工作?你有没有试过调试它?什么线路给你意想不到的结果?你真的没有提供足够的细节...... – Vladimir 2011-03-22 09:59:50
如果你选择不同的皮肤,为什么中心点不同? – JohnnyBizzle 2011-03-22 10:02:23
有一点,当触摸揭示skin2/theme2,当再次触摸揭示skin1/theme1等...也许是因为中心点关闭。我会认为中心点关闭也会在模拟器上产生与设备上相同的结果。 – hanumanDev 2011-03-22 10:11:56