gpt4 book ai didi

objective-c - 在 UIButton 上使用 LSR 图像

转载 作者:太空狗 更新时间:2023-10-30 04:00:53 24 4
gpt4 key购买 nike

我正在创建一个 tvOS 应用程序,我想在几个按钮上使用视差图像。来自 the docs :

To incorporate parallax images in your app:

  1. Create a UIImage object.
  2. You load the image differently depending on whether the image is included in your app bundle or whether you have downloaded the image.
    • Bundle—Load images using imageNamed:.
    • Downloaded file—Load images using imageWithContentsOfFile:.
  3. Create a new UIImageView object using the loaded images.
  4. If the UIImageView is part of another view, set adjustsImageWhenAncestorFocused to YES on the UIImageView.

我知道那里说的是 UIImageView,但我希望在 UIButton 上产生同样的效果,就像主屏幕应用程序图标一样。

我已经创建了艺术品,在 Assets 目录中制作了一个堆栈,并使用 imageNamed: 加载了图像,但是 UIButton 的行为不像视差图像.它不像主屏幕图标那样左右摇摆。它看起来就像一个平面图像。

为了使 UIButton 表现得像主屏幕应用程序图标,我还需要启用其他功能吗?

UIButton* quitGame = [[UIButton alloc] initWithFrame:rectWithNewX(playAgain.frame, 985)];
[quitGame setImage:[UIImage imageNamed:@"quit.lsr"] forState:UIControlStateNormal];
[quitGame setAdjustsImageWhenHighlighted:YES];
fadeIn(quitGame, self.view, 0.5);

最佳答案

截至目前,仅使用 UIButtons 是不可能的,但是,我确实找到了解决方法。

相反,创建一个 UIImageView 来填充 UIButton 的大小并使其成为 UIButton 的 subview 。然后调用 adjustsImageWhenAncestorFocused: 并将其设置为 true。瞧!

UIButton* playAgain = [[UIButton alloc] initWithFrame:CGRectMake(centerX(650, self.view), sh() - 250, 300, 180)];
[playAgain setAdjustsImageWhenHighlighted:YES];
[playAgain addTarget:self action:@selector(playAgain) forControlEvents:UIControlEventPrimaryActionTriggered];
fadeIn(playAgain, self.view, 0.5);

UIImageView* playAgainIGV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 180)];
[playAgainIGV setImage:[UIImage imageNamed:@"playagain.lsr"]];
[playAgainIGV setAdjustsImageWhenAncestorFocused:YES];
[playAgain addSubview:playAgainIGV];

关于objective-c - 在 UIButton 上使用 LSR 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32729910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com