1
私は現在、UIButtonsが正方形に配置されたプログラムを書いています。 NIBで私は、「タッチアップ・インサイド(Touch Up Inside)」イベントを使用して、1つ1つをテーピングし、次にもう1つをテーピングしてボタンを交換しますUIButtonの位置をスワイプやドラッグでどのように入れ替えるのですか?
別のものの方向にスワイプし、もう一方をドラッグしてスワップさせたいと思います。私はこれを行う方法を理解することができませんでした。アップルのドキュメントを数週間見てきましたが、どういう意味が分かりません。
誰かが私のコードにこれを行うために必要なものを教えてもらえますか?ここで
は私のコードです:スワイプやドラッグなどの
#import "squareViewController.h"
static UIButton *matrix[2][2];
static int firstButtonRow, firstButtonColumn, secondButtonRow, secondButtonColumn;
static BOOL isFirstTouch = YES;
static CGPoint gestureStartPoint;
@implementation squareViewController
@synthesize diamond;
@synthesize heart;
@synthesize spade;
@synthesize club;
- (void)viewDidLoad {
matrix[0][0] = [diamond retain];
matrix[0][1] = [heart retain];
matrix[1][0] = [spade retain];
matrix[1][1] = [club retain];
}
- (void)ButtonTapped:(id)sender{
int row = 0, column = 0;
for(row = 0; row < 2; row++){
for(column = 0; column < 2; column++){
if (matrix[row][column] == sender){
if (isFirstTouch == YES){
firstButtonRow = row;
firstButtonColumn = column;
isFirstTouch = NO;
return;
}
else{
secondButtonRow = row;
secondButtonColumn = column;
[self SwapButtons: firstButtonRow:
firstButtonColumn:
secondButtonRow:
secondButtonColumn];
isFirstTouch = YES;
return;
}
}
}
}
}
- (void)ButtonSwiped:(id)sender {
// ?????
}
- (void)ButtonDragged:(id)sender {
// ?????
}
- (void)SwapButtons:(int)firstRow: (int)firstColumn: (int)secondRow: (int)secondColumn{
UIButton *tempButton = [[[UIButton alloc] init] retain]; // allocate memory for tempButton
UIButton *tempButtonOrig = tempButton; // mirror tempButton to preserve adderess for release;
[UIView beginAnimations:@"main" context:nil];
tempButton.frame = matrix[firstRow][firstColumn].frame;
matrix[firstRow][firstColumn].frame
= matrix[secondRow][secondColumn].frame;
matrix[secondRow][secondColumn].frame = tempButton.frame;
tempButton = matrix[firstRow][firstColumn];
matrix[firstRow][firstColumn]
= matrix[secondRow][secondColumn];
matrix[secondRow][secondColumn] = tempButton;
[tempButtonOrig release];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
私がそれらを上回っている場合、「Touch Up Inside」イベントは、自動的に処理されるのでしょうか、それともそれらも追跡する必要がありますか? また、(id)送信者、スワイプとドラッグについてもテストできますか、それらは無くなるでしょうか? –