Iphone touchesbreated&x27;我不总是回答
我在屏幕上检测到一个滑动,它完全按照我想要的方式工作。 唯一的问题是,在测试中,我不断地反复滑动,至少有90%或更多的时间它有响应,但时不时地没有响应 我记录了所有事情以找到罪犯,并发现TouchesStart在发生这种情况的几次中根本没有被检测到 这是我的代码,虽然TouchesStart甚至没有被调用,所以代码应该不重要:Iphone touchesbreated&x27;我不总是回答,iphone,touch,swipe,touchesbegan,Iphone,Touch,Swipe,Touchesbegan,我在屏幕上检测到一个滑动,它完全按照我想要的方式工作。 唯一的问题是,在测试中,我不断地反复滑动,至少有90%或更多的时间它有响应,但时不时地没有响应 我记录了所有事情以找到罪犯,并发现TouchesStart在发生这种情况的几次中根本没有被检测到 这是我的代码,虽然TouchesStart甚至没有被调用,所以代码应该不重要: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touche
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touches began!");
UITouch *touch = [touches anyObject];
CGPoint thisTouch = [touch locationInView:self.view];
touchstartedX = thisTouch.x;
touchstartedY = thisTouch.y;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint p = [[touches anyObject] locationInView:self.view];
if ((abs(p.y - touchstartedY)) < 120) {
if ((p.x - touchstartedX) > 10) {
[self goPrevious];
} else if ((p.x - touchstartedX) < -10) {
[self goNext];
}
} else { NSLog(@"too much Y"); }
}
使用苹果的产品要容易得多
使用苹果的产品要容易得多
很高兴它起了作用。苹果真的用手势识别器打出了全垒打。让我们的生活轻松多了。很高兴它帮助了我们。苹果真的用手势识别器打出了全垒打。让我们的生活更轻松。
UIViewController <UIGestureRecognizerDelegate>
UISwipeGestureRecognizer *swipeLeft;
UISwipeGestureRecognizer *swipeRight;
@property (nonatomic, retain) UISwipeGestureRecognizer *swipeLeft;
@property (nonatomic, retain) UISwipeGestureRecognizer *swipeRight;
@synthesize swipeLeft, swipeRight;
UIGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
self.swipeLeft = (UISwipeGestureRecognizer *)recognizer;
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
self.swipeLeft = (UISwipeGestureRecognizer *)recognizer;
[recognizer release];
recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
self.swipeRight = (UISwipeGestureRecognizer *)recognizer;
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
self.swipeRight = (UISwipeGestureRecognizer *)recognizer;
[recognizer release];
[self.view addGestureRecognizer:swipeLeft];
[self.view addGestureRecognizer:swipeRight];
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
[self goNext];
} else {
[self goPrevious];
}
}
- (void)dealloc
{
[swipeLeft release];
[swipeRight release];
[super dealloc];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.swipeLeft = nil;
self.swipeRight = nil;
}
// add Swipe Left
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
[swipeLeft release];
// add Swipe Right
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
[swipeRight release];
- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)recognizer {
//do something
}
- (void)handleSwipeRight:(UISwipeGestureRecognizer *)recognizer {
//do something
}