何かをタップすると、タップした場所に小さな50X53の画像が表示されるゲームを作ろうとしています。まず、50x53の画像をボタンにして、ボタンをタッチするとボタンの背景が赤に変わります(画像がそこに追加されたことをシミュレートします)ここで、viewControllerに約48個のボタン(6X8)があり、これらのボタンの1つを押すと、背景が赤に変わります。 UIは完全に空白になり(ボタンは表示されません)、特定の領域を押すと、押した小さなスペースに画像がポップアップ表示されます。私はする代わりに考えました
-(IBAction)imagePressed
{
sender.background=[UIColor redColor];
}
-(IBAction)imagePressedAgain
{
sender.background=[UIColor whiteColor];
}
私は次のようなことをするつもりでした
-(IBAction)imagePressed
{
sender.image=@"whateverImage.png";
//I know this isn't the right syntax to change a buttons image (and i don't even know if i can change a buttons image) but anyways i was going to try to here
}
-(IBAction)imagePressedAgain
{
sender.image=@"imageThatIsJustAWhiteBackground";
}
だから私はこれをやってみて、それから自分自身に思いました、うーん、多分私はそれをこのようにするべきではないでしょう、私はたくさんの小さなUIImageViewsを使ってそれらすべてをinterfaceBuilderに置くべきですか?画面全体に48個のボタンを配置する代わりに、48個のUIImageViewを配置しますか?次に、それぞれにタップジェスチャレコグナイザーを追加すると思いますか?または、古い計画に固執してボタンの画像を変更する必要がありますか?
(o、そしてところで、ユーザーが画面上の指を触れた場所に正確に比例して画像を表示することはできません。整理されたグリッドに配置する必要があるため、48個の画像を表示する必要があります。)