float red = arc4random()%256/255.0;
float green = arc4random()%256/255.0;
float blue = arc4random()%256/255.0;
self.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1];
这是设置背景色为任意颜色,可以看到这里首先给三个颜色有关的值取任意的0到1之间的数,然后使用colorWithRed: green: blue: 来设定颜色。
设置多点触摸的时候一定要先让multipleTouchEnabled设置为YES;
CGRect bounds = self.bounds;
bounds.size.width += dDis;
bounds.size.height += dDis;
self.bounds = bounds;
distance = currentDistance;
设置两个手指捏合的时候让中心保持不变,改变宽和高,注意要改变宽高之后再给一句self.bounds=bounds这一句让宽和高是事实更新的;还有距离也要更新。
在添加不同手势的时候,后一次手势执行前要取消前一次的。例如添加轻拍手势,有点击一次和两次,在执行两次的手势时要先取消一次的手势,以免造成影响
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
int tapCount = touch.tapCount;
NSLog(@"%d",tapCount);
if(tapCount == 1)
{
//[self singleTap];
[self performSelector:@selector(singleTap) withObject:nil afterDelay:0.3];
}
if(tapCount == 2)
{
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTap) object:nil];
[self doubleTap];
}
}