iOS 通过Touch改变一个视图的颜色

在视图的初始化方法里设置想要显示的初始颜色,然后……

 

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

 

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!
技术狗 » iOS 通过Touch改变一个视图的颜色