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];

 

posted @ 2016-02-05 20:38  aRenOuBa  阅读(548)  评论(0编辑  收藏  举报