1.效果是点击移动,整个屏幕的颜色随机变化
<pre name="code" class="objc">- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//鼠标移动时,随机获得颜色
float red = arc4random() % 255;
float green = arc4random() % 255;
float blue = arc4random() % 255;
UIColor *color = [UIColor colorWithRed:red/255 green:green/255 blue:blue/255 alpha:
1];
;
self.view.backgroundColor = color;
}
2.效果是移动鼠标时,屏幕上创建出来一个view,只有view的颜色随机变化
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//从父视图上删除之前move所创建的view
for (UIView *object in self.imageView.subviews){
[object removeFromSuperview];
}
//创建一个点,来接收每次移动的点
CGPoint point = [[touches anyObject] locationInView:self.imageView];
//创建一个视图,每次移动,视图的中心都是move后所获的得point
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 80, 80)];
//鼠标移动时,随机获得颜色
float red = arc4random() % 255;
float green = arc4random() % 255;
float blue = arc4random() % 255;
UIColor *color = [UIColor colorWithRed:red/255 green:green/255 blue:blue/255 alpha:
1];
;
view.backgroundColor = color;
[self.imageView addSubview:view];
view.center = point;
}