【发布时间】:2013-03-15 23:11:17
【问题描述】:
我正在尝试查看用户是否从一个视图、标签等一直滑动到另一个。
这是我的相关代码
ViewController.h:
@property (strong, nonatomic) IBOutlet UITextField *textField;
@property (strong, nonatomic) IBOutlet UILabel *swipeBegin;
@property (strong, nonatomic) IBOutlet UILabel *swipeEnd;
TextField : 显示整个事情是否成功。
SwipeBegin :滑动开始的标签。
SwipeEnd : 滑动应该结束的标签。
ViewController.m :
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if ([touch view] == swipeBegin) {
gestureStartPointTouched = YES;
}
如果滑动开始于“swipeBegin”,则布尔值设置为 YES。
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if ([touch view] == swipeEnd) {
if (gestureStartPointTouched == YES) {
[TextField setText:@"Success"];
}
}
如果我开始在“swipeBegin”处滑动,则调用 touchesBegan 方法 -> 工作正常
麻烦的部分是 touchesEnded 方法。
if([touch view] == swipeEnd)
不管我怎么做都是假的。
有人给点建议吗?
谢谢!
解决方案
编辑 touchesEnded 方法:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if ([self.view hitTest:[[touches anyObject] locationInView:self.view] withEvent:event] == SwipeEnd) {
if (gestureStartPointTouched == YES) {
[TextField setText:@"Success"];
}
}
【问题讨论】:
标签: ios objective-c cocoa-touch uiview uikit