Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在UIView中实现滑动和轻触_Iphone_Objective C - Fatal编程技术网

Iphone 在UIView中实现滑动和轻触

Iphone 在UIView中实现滑动和轻触,iphone,objective-c,Iphone,Objective C,我想让UIImageView同时检测轻触和滑动手势。我已经编写了用于滑动检测的touchesbeent方法,我只想知道如何让ImageView同时检测这两种手势 如何对ToucheSStart进行编码,使其能够同时处理这两个问题 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if ([touches count] != 1) return; floatSwipeStartX = [[touches

我想让UIImageView同时检测轻触和滑动手势。我已经编写了用于滑动检测的touchesbeent方法,我只想知道如何让ImageView同时检测这两种手势

如何对ToucheSStart进行编码,使其能够同时处理这两个问题

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if ([touches count] != 1)
    return;

floatSwipeStartX = [[touches anyObject] locationInView:self.view].x;
floatSwipeStartY = [[touches anyObject] locationInView:self.view].y;

intSwipeDirection = 0;

isSwiping = YES;

viewUp.hidden = NO;
viewLeft.hidden = NO;
viewCurrent.hidden = NO;
viewRight.hidden = NO;
viewDown.hidden = NO;
}

}

-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event{
CGFloat swipedInstancex=[[toucheanyobject]locationInView:self.view].x-floatSwipeStartX;
CGFloat SwipedInstancey=[[Touchs anyObject]locationInView:self.view].y-floatSwipesParty;
如果(!isSwiping | |(SwipedStancex==0&&SwipedStancey==0)){
//[自我更新新闻];
返回;
}
if(intSwipeDirection==滑动方向水平){
如果(SwipedStancex>50.0f){
intNewDirection=向右滑动;
intCurrentView=intCurrentLeft;
}否则如果(SwipedStancex<-50.0f){
intNewDirection=向左滑动;
intCurrentView=intCurrentRight;
}
}else{//垂直
如果(开关电阻>50.0f){
intNewDirection=向上滑动鼠标;
intCurrentView=intCurrentUp;
}否则如果(开关电阻<-50.0f){
intNewDirection=滑动鼠标向下滑动鼠标;
intCurrentView=intCurrentDown;
}
}
[自我更新新闻];
isSwiping=否;
}


请指导我在何处插入点击手势代码。我使用的是simulator 3.2

如果您使用的是sdk 3.2或更高版本,使用UIgestureRecognitor类非常容易


否则,我会做一些事情,检查手指在触摸开始和触摸结束之间的移动量,如果移动量最小,则称其为轻拍,如果移动量较大,则称其为轻扫。

非常感谢,伙计。。。。它奏效了……:)我在if块中插入了必须执行的操作。。如果(!isSwiping | |(swipeDistanceX==0&&swipeDistanceY==0)){}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (!isSwiping || [touches count] != 1){
    return;
}
CGFloat swipeDistanceX = [[touches anyObject] locationInView:self.view].x - floatSwipeStartX;
CGFloat swipeDistanceY = [[touches anyObject] locationInView:self.view].y - floatSwipeStartY;

CGSize contentSize = [self setContentSize];

if (! intSwipeDirection) {

    if (abs(swipeDistanceX) > abs(swipeDistanceY)) { // swipe left or right
        intSwipeDirection = SWIPE_DIRECTION_HORIZONTAL;
    } else {
        intSwipeDirection = SWIPE_DIRECTION_VERTICAL;
    }

}

if (intSwipeDirection == SWIPE_DIRECTION_HORIZONTAL) {
    viewLeft.frame = CGRectMake(swipeDistanceX - contentSize.width, 0.0f, contentSize.width, contentSize.height);
    viewCurrent.frame = CGRectMake(swipeDistanceX, 0.0f, contentSize.width, contentSize.height);
    viewRight.frame = CGRectMake(swipeDistanceX + contentSize.width, 0.0f, contentSize.width, contentSize.height);
} else {
    viewUp.frame = CGRectMake(0.0f, swipeDistanceY - contentSize.height, contentSize.width, contentSize.height);
    viewCurrent.frame = CGRectMake(0.0f, swipeDistanceY, contentSize.width, contentSize.height);
    viewDown.frame = CGRectMake(0.0f, swipeDistanceY + contentSize.height, contentSize.width, contentSize.height);
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

CGFloat swipeDistanceX = [[touches anyObject] locationInView:self.view].x - floatSwipeStartX;
CGFloat swipeDistanceY = [[touches anyObject] locationInView:self.view].y - floatSwipeStartY;

if (! isSwiping || (swipeDistanceX == 0 && swipeDistanceY == 0)) {

    //[self updateViews];

    return;
}

if (intSwipeDirection == SWIPE_DIRECTION_HORIZONTAL) {

    if (swipeDistanceX > 50.0f) {
        intNewDirection = SWIPE_TO_THE_RIGHT;
        intCurrentView = intCurrentLeft;
    } else if (swipeDistanceX < -50.0f) {
        intNewDirection = SWIPE_TO_THE_LEFT;
        intCurrentView = intCurrentRight;
    }

} else { // vertical


    if (swipeDistanceY > 50.0f) {
        intNewDirection = SWIPE_TO_THE_UP;
        intCurrentView = intCurrentUp;
    } else if (swipeDistanceY < -50.0f) {
        intNewDirection = SWIPE_TO_THE_DOWN;
        intCurrentView = intCurrentDown;
    }

}

[self updateViews];

isSwiping = NO;