Friday, December 6, 2013

On the relationship between gesture and dynamically added button issues

Details are as follows: There is a imageview, imageview below a row of button, each button on the image imageview conducted on different algorithms handle. button is added dynamically, in action, and it is connected (for this action for the time being named as - (IBAction) processImage: (id) sender), the corresponding tag button switch, depending on the judge to determine what kind of algorithm execution .



The question now is: add a UISwipeGestureRecognizer gesture, hoping to achieve swipe about imageview (Of course, there may be self.view, this is not the point) the automatic processing of a button corresponding algorithm.


So how to achieve it?
Reply:
The landlord, UISwipeGestureRecognizer you have a custom monitor events in this incident, put your current button tag +1, then call a particular tag algorithm, you can write a separate method algorithm
Reply:
 UISwipeGestureRecognizer * swipeGestureRecognizer = nil; 

swipeGestureRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (swipe :)] autorelease];
[SwipeGestureRecognizer setDirection: UISwipeGestureRecognizerDirectionUp];
[Self.view addGestureRecognizer: swipeGestureRecognizer];

swipeGestureRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (swipe :)] autorelease];
[SwipeGestureRecognizer setDirection: UISwipeGestureRecognizerDirectionDown];
[Self.view addGestureRecognizer: swipeGestureRecognizer];

swipeGestureRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (swipe :)] autorelease];
[SwipeGestureRecognizer setDirection: UISwipeGestureRecognizerDirectionLeft];
[Self.view addGestureRecognizer: swipeGestureRecognizer];

swipeGestureRecognizer = [[[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (swipe :)] autorelease];
[SwipeGestureRecognizer setDirection: UISwipeGestureRecognizerDirectionRight];
[Self.view addGestureRecognizer: swipeGestureRecognizer];

- (Void) swipe: (UISwipeGestureRecognizer *) swipeGestureRecognizer
{
switch (swipeGestureRecognizer.direction) {
case UISwipeGestureRecognizerDirectionUp:
NSLog (@ "UISwipeGestureRecognizerDirectionUp");
/ / Your method
break;
case UISwipeGestureRecognizerDirectionDown:
NSLog (@ "UISwipeGestureRecognizerDirectionDown");
/ / Your method
break;
case UISwipeGestureRecognizerDirectionLeft:
NSLog (@ "UISwipeGestureRecognizerDirectionLeft");
/ / Your method
break;
case UISwipeGestureRecognizerDirectionRight:
NSLog (@ "UISwipeGestureRecognizerDirectionRight");
/ / Your method
break;
default:
break;
}
}


Swipe their own methods to achieve it.
Reply:
Although the two did not understand what I mean, but I have to get out, or thank you, end quote ~ ~ ~

No comments:

Post a Comment