UITouch手指滑动屏幕,屏幕跟着移动
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UITouch手指滑动屏幕,屏幕跟着移动相关的知识,希望对你有一定的参考价值。
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手指滑动屏幕,屏幕跟着移动的主要内容,如果未能解决你的问题,请参考以下文章