CGRect のタッチ位置に基づいてイメージと var を変更するメソッドを作成しています。現在、一連の if ステートメントを使用して、タッチ位置を手動で反転しています。これがこれを行うための特に効率的な方法であるとは確信していません。
画像の変更には問題なく動作しますが、var の変更 (まだ実装していません) では、1 から 100 まで +1 刻みでスケーリングする必要があります。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView: self.view];
if (CGRectContainsPoint(CGRectMake(0, 20, 117, 200), point)) {
if (point.y >= 20 && point.y <= 32) //12
imageA.image = [UIImage imageNamed:@"ChemA-15.png"];
if (point.y >= 33 && point.y <= 45)
imageA.image = [UIImage imageNamed:@"ChemA-14.png"];
if (point.y >= 46 && point.y <= 58)
imageA.image = [UIImage imageNamed:@"ChemA-13.png"];
if (point.y >= 59 && point.y <= 70)
imageA.image = [UIImage imageNamed:@"ChemA-12.png"];
if (point.y >= 71 && point.y <= 82)
imageA.image = [UIImage imageNamed:@"ChemA-11.png"];
if (point.y >= 83 && point.y <= 94)
imageA.image = [UIImage imageNamed:@"ChemA-10.png"];
if (point.y >= 95 && point.y <= 106)
imageA.image = [UIImage imageNamed:@"ChemA-9.png"];
if (point.y >= 107 && point.y <= 118)
imageA.image = [UIImage imageNamed:@"ChemA-8.png"];
if (point.y >= 119 && point.y <= 130)
imageA.image = [UIImage imageNamed:@"ChemA-7.png"];
if (point.y >= 131 && point.y <= 142)
imageA.image = [UIImage imageNamed:@"ChemA-6.png"];
if (point.y >= 143 && point.y <= 154)
imageA.image = [UIImage imageNamed:@"ChemA-5.png"];
if (point.y >= 155 && point.y <= 166)
imageA.image = [UIImage imageNamed:@"ChemA-4.png"];
if (point.y >= 167 && point.y <= 178)
imageA.image = [UIImage imageNamed:@"ChemA-3.png"];
if (point.y >= 179 && point.y <= 190)
imageA.image = [UIImage imageNamed:@"ChemA-2.png"];
if (point.y >= 191 && point.y <= 202)
imageA.image = [UIImage imageNamed:@"ChemA-1.png"];
}
}
これを行うより良い方法はありますか?提供されたヘルプに感謝します。