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文章

iOS 3D Touch之Peek &Pop

2019-12-24 13:06:31

iOS文章

iOS 设置屏幕是否长亮

2019-12-24 15:13:24

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索