gpt4 book ai didi

ios - 是否可以更改特定 x 和 y 坐标的颜色?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:09:01 25 4
gpt4 key购买 nike

例如看看这个:

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
path = [UIBezierPath bezierPathWithRect:CGRectMake(touchPoint.x, touchPoint.y, 1, 1)];

NSLog(@"Touch moving point =x : %f Touch moving point =y : %f", touchPoint.x, touchPoint.y);

}

我尝试了什么:C

GRect topRect = CGRectMake(touchPoint.x,touchPoint.y, 10,10);
// Fill the rectangle with grey
[[UIColor redColor] setFill];
UIRectFill( topRect );
[self.view drawRect:topRect];

但它给我错误:

<Error>: CGContextSetCompositeOperation: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

当用户移动触摸时,我得到坐标并改变颜色。当用户移动他们的手时,x 和 y 坐标正在生成,对于那个特定的地方,我想改变颜色。

如果可能请给一些提示。

最佳答案

任何绘图操作都必须在 view drawing cycle 内完成.您不能在任何时候绘制内容,只能在绘制 View 时执行此操作。

这意味着在你的 UIView 子类中覆盖 drawRect: 方法,如果你没有,那么你需要添加它:

- (void)drawRect:(CGRect)rect {
GRect topRect = CGRectMake(self.touchedPoint.x,touchedPoint.y, 10,10);
// Fill the rectangle with grey
[[UIColor redColor] setFill];
UIRectFill( topRect );
[self.view drawRect:topRect];
}

下一步是将信息从您的 Controller (接收 touchesMoved: 消息的 Controller )传递到 View 。这可以通过 View 上的属性来完成:

@property (nonatomic) CGPoint touchedPoint;

最后,在传递点详细信息后,您需要通过调用 setNeedsDisplay 告诉 View 它需要重绘。 :

((MyViewSubclass*)self.view).touchedPoint = touchPoint;
[self.view setNeedsDisplay];

关于ios - 是否可以更改特定 x 和 y 坐标的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34674554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com