moveshow-监听手指位置趣味小程序

来源:互联网 发布:golang 1.7.4 编辑:程序博客网 时间:2024/04/29 06:07
突发奇想想要在公司的应用上添加一个原本在网页上的效果,就是手指滑动到某一个图标上,没有点击就会显示一个效果,可能是一段文字,或者是图标的特效展示。具体的就像是mac系统下方那个导航一样,随着手指的滑动而变大缩小。

很简单的应用,也没花几分钟时间,但是觉得很有意思
可能对于新手来说,可以顺便看看touch捕捉事件函数
moveshow-监听手指位置趣味小程序 - 柠檬加冰 - 柠檬加冰的博客
 
应该是不需要上传源代码的。。关键代码就几行

@interface ViewController : UIViewController

{

    CGPoint beginPoint;

    CGPoint nowPoint;

    BOOL isInButton;

}

@property (strong,nonatomic) IBOutlet UIButton *mButton;



- (void)viewDidLoad

{

    [super viewDidLoad];

    isInButton = YES;

// Do any additional setup after loading the view, typically from a nib.

}

- (IBAction)buttonclick:(id)sender

{

    NSLog(@"button tap");

}

- (void)shownslog

{

    if (isInButton) {

        [mButton setBackgroundImage:[UIImage imageNamed:@"meinv.jpg"] forState:UIControlStateNormal];

        NSLog(@"move in button");

    }else{

        [mButton setBackgroundImage:[UIImage imageNamed:@"images.jpeg"] forState:UIControlStateNormal];

        NSLog(@"move out button");

    }


}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    

    beginPoint = [touch locationInView:self.view];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    

    nowPoint = [touch locationInView:self.view];

    

    if (nowPoint.x <314&&nowPoint.x>6&&nowPoint.y>90&&nowPoint.y<313) {

        if (!isInButton) {

            isInButton = YES;

            [self shownslog]; 

        }

    }

    else

    {

        if (isInButton) {

            isInButton = NO;

            [self shownslog];

        }

    }

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

{

    

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

    if (isInButton) {

        isInButton = NO;

        [self shownslog];

    }

}


代码稍后会上传到cocoachina。关键字:moveshow

0 0