美文网首页
iOS 通过Touch改变一个视图的颜色

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

作者: 邓布利多教授 | 来源:发表于2019-04-17 11:57 被阅读0次

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

- (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改变一个视图的颜色

      本文链接:https://www.haomeiwen.com/subject/xewgwqtx.html