您的位置:首页 > 移动开发 > 微信开发

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

2016-04-26 18:09 417 查看
突发奇想想要在公司的应用上添加一个原本在网页上的效果,就是手指滑动到某一个图标上,没有点击就会显示一个效果,可能是一段文字,或者是图标的特效展示。具体的就像是mac系统下方那个导航一样,随着手指的滑动而变大缩小。
很简单的应用,也没花几分钟时间,但是觉得很有意思可能对于新手来说,可以顺便看看touch捕捉事件函数

应该是不需要上传源代码的。。关键代码就几行
@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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: