代码可以在 iPhone 模拟器上运行,但不能在设备上运行

发布于 2024-10-25 07:36:45 字数 822 浏览 2 评论 0原文

我使用以下代码在 ipad 应用程序中的两个不同的皮肤/主题之间切换。 该代码在模拟器中运行良好,但在设备上运行不佳。任何人都可以就为什么会发生这种情况提出任何建议吗?

    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;


    }

I'm using the following code to switch between two different skins/themes in an ipad app.
The code works fine in the simulator but not on the device. Can anyone give any suggestions as to why this might be happening?

    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;


    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

满地尘埃落定 2024-11-01 07:36:45

我曾经遇到过一个问题,模拟器正确地选择了资源(图像),但没有正确地选择设备(iPhone)。

至少在我的例子中,结果是图像名称的情况。确保图像的名称与代码中写入的完全相同(button.png / Button.png 等)

只是猜测......

I once faced a problem where Simulator was correctly picking the resources (images) but not the device (iPhone).

At least in my case it turned out to be the case of image names. Make sure the name of image is exactly as written in code (button.png / Button.png etc.)

Just a guess...

小伙你站住 2024-11-01 07:36:45

您的图像可能存在一些问题,它在模拟器中显示正常,但在设备中则不然...只需 4 尝试使用另一个图像代替该图像。
谢谢

may b some problem with your images it shows fine in simulator but not in device ...just 4 a try use another image in place of that .
thanks

岁月如刀 2024-11-01 07:36:45

试试这个:

首先,不要在每次想要更改主题时都分配imgSkinSelector。在 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];

}
else {

[self.imgSkinSelector setImage:[UIImage imageNamed:@"button2.png"]];
self.imgSkinSelector.center = CGPointMake(74, 74);
[self.landscape addSubview:self.imgSkinSelector];

}

希望这对您有用。

Try this:

Firstly, don't alloc imgSkinSelector every time you want to change your theme. Alloc/init only once in your viewDidLoad/loadView function like below:

self.imgSkinSelector = [[UIImageView alloc] init];

Then in your function, where you are changing theme, use this code:

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];

}
else {

[self.imgSkinSelector setImage:[UIImage imageNamed:@"button2.png"]];
self.imgSkinSelector.center = CGPointMake(74, 74);
[self.landscape addSubview:self.imgSkinSelector];

}

Hope this works for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文