我可以在 Xcode 中更改背景颜色的同时保持 UI 元素可访问吗?
Can I keep UI elements accessable while changing background color in Xcode?
我在 Xcode 中有一个游戏,在白色背景上有几个 UIButton。当用户单击正确的按钮时,我将背景从白色更改为蓝绿色(动画)。我想让用户继续点击,同时背景颜色发生变化,但看起来按钮在背景色动画完成之前无法访问 运行。
有没有办法解决它并将焦点放在按钮上?背景动画能否在后台发生,独立于游戏的其余部分?
在此先感谢您对理解这一点的帮助。
这是我的代码:
[UIView animateWithDuration:0.3f
animations:^{
self.view.backgroundColor = [UIColor colorWithRed:0.1f green:0.15f blue:0.05f alpha:1.0f];
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.3f
animations:^{
self.view.backgroundColor = [UIColor colorWithRed:1.0f green:1.0 blue:1.0 alpha:1.0f];
}
];
}
];
所有的 UIButton 都是在前面单独的方法中添加的
UIButton *btnI;
[self.view addSubview:btnI];
使用
dispatch_async(backgroundQueue, {
//change the background colour here
})
您可以使用动画方法 options:
+ animateWithDuration:delay:options:animations:completion:
带有 UIViewAnimationOptionAllowUserInteraction 选项。
If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.
我在 Xcode 中有一个游戏,在白色背景上有几个 UIButton。当用户单击正确的按钮时,我将背景从白色更改为蓝绿色(动画)。我想让用户继续点击,同时背景颜色发生变化,但看起来按钮在背景色动画完成之前无法访问 运行。 有没有办法解决它并将焦点放在按钮上?背景动画能否在后台发生,独立于游戏的其余部分?
在此先感谢您对理解这一点的帮助。 这是我的代码:
[UIView animateWithDuration:0.3f
animations:^{
self.view.backgroundColor = [UIColor colorWithRed:0.1f green:0.15f blue:0.05f alpha:1.0f];
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.3f
animations:^{
self.view.backgroundColor = [UIColor colorWithRed:1.0f green:1.0 blue:1.0 alpha:1.0f];
}
];
}
];
所有的 UIButton 都是在前面单独的方法中添加的
UIButton *btnI;
[self.view addSubview:btnI];
使用
dispatch_async(backgroundQueue, {
//change the background colour here
})
您可以使用动画方法 options:
+ animateWithDuration:delay:options:animations:completion:
带有 UIViewAnimationOptionAllowUserInteraction 选项。
If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.