imageView点击 滑动事件

  imageView点击 滑动事件:

   UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(done)];

   [imageView addGestureRecognizer:tap];


 -(void) done
{
    int clickedIndex = 0;
    for (int i = 0; i < [self.buttonArray count]; i++)
    {
        if (touchView == [self.buttonArray objectAtIndex:i])
            clickedIndex = i;
    }
    
    if (clickedIndex < centerIndex)
    {
        for (int i = 0; i < centerIndex - clickedIndex; i++)
        {
            if ([self.buttonArray objectAtIndex:[self.buttonArray count] - 1] != nil)
            {
                [self.buttonArray insertObject:[self.buttonArray objectAtIndex:[self.buttonArray count] - 1] atIndex:0];
                [self.buttonArray removeObjectAtIndex:[self.buttonArray count] - 1 ];
                [self resetButtonFrame];
                
            }
            
        }
    }
    else if(clickedIndex > centerIndex)
    {
        for (int i = 0; i < clickedIndex - centerIndex; i++)
        {
            [self.buttonArray addObject:[self.buttonArray objectAtIndex:0]];
            [self.buttonArray removeObjectAtIndex:0];
            [self resetButtonFrame];
        }
    }
    else
    {
        int index = 0;
        for (int i = 0; i < [self.saveImageArray count]; i++)
        {
            if (touchView.image == [self.saveImageArray objectAtIndex:i])
                index = i;
        }
    }
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    touchView = (UIImageView*)[touch view];
}


-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint previousPoint = [touch previousLocationInView:self];
    CGPoint currentPoint = [touch locationInView:self];
    CGFloat x = currentPoint.x - previousPoint.x;
    if (currentPointCompare.x == previousPoint.x && currentPointCompare.y == previousPoint.y) {
        
    }else
    {
        if (x > 10)
        {
            [self.buttonArray insertObject:[self.buttonArray objectAtIndex:[self.buttonArray count] - 1] atIndex:0];
            [self.buttonArray removeObjectAtIndex:[self.buttonArray count] - 1 ];
            
        }else if(x < (-10))
        {
            [self.buttonArray addObject:[self.buttonArray objectAtIndex:0]];
            [self.buttonArray removeObjectAtIndex:0];
        }
        [self resetButtonFrame];
    }
    
    currentPointCompare = currentPoint;
}

子类的点击,滑动事件可通过self.nextResponder转到父类执行,如下
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.nextResponder touchesBegan:touches withEvent:event];
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.nextResponder touchesMoved:touches withEvent:event];
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值