1
저는 현재 UIButtons가 정사각형으로 배열 된 프로그램을 작성하고 있습니다. NIB에서. 나는 "Touch Up Inside"이벤트를 사용하여 하나를 테이핑하고 다른 하나를 테이핑하여 버튼을 교환합니다.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) 발신인을 테스트 할 수 있습니까? 스 와이프 및 드래그를 할 수 있습니까? –