在视图的初始化方法里设置想要显示的初始颜色,然后……
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
UITouch *touch = [touches anyObject];
NSLog(@"fff = %f",touch.force);
self.backgroundColor = [UIColor colorWithRed:(touch.force / touch.maximumPossibleForce )green:0 blue:1 alpha:1];
if (touch.force == touch.maximumPossibleForce){
NSLog(@"%f",touch.force);
}
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:1];
}