码迷,mamicode.com
首页 > 移动开发 > 详细

UITouch手指滑动屏幕,屏幕跟着移动

时间:2016-02-05 22:17:47      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

1.//当手指在屏幕上滑动时

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

UITouch *touch  = [touches anyObject];

CGPoint previousPoint = [touch previousLocationInView:self];

CGPoint currentPoint = [touch locationInView:self];

CGPoint newCenter = CGPointMake(0,0);

newCenter.x = self.center.x + (currentPoint.x - previousPoint.x);

newCenter.y = self.center.y + (currentPoint.y - previousPoint.y);

self.center = newCenter;

}

2.按钮的点击状态,点击一下不返回初始状态的情景

1)先设置按钮两个状态下的背景图片

button setImage:[[UIImage ImageNamed:"1.png"] forState:UIControlStateNormal];

button setImage:[[UIImage ImageNamed:"2.png"] forState:UIControlStateSelected];

[button addTarget:self action:@selector(click:) forControlEvent:UIControlEventTouchUpInSide];

2)实现点击方法

- (void)click {

button.selected = !button.selected;

}

2.加法计算器的实现重要步骤

1)将输入框的值强转为int类型的,然后将两个输入框的值的和强转为字符串类型的

label.text = [NSString stringWithFormat:@"%d",sum];

 

UITouch手指滑动屏幕,屏幕跟着移动

标签:

原文地址:http://www.cnblogs.com/arenouba/p/5183582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!