我需要在UIView中创建自己的坐标系,其中0,0是UIView的中心。但我不知道这样做。请帮忙。
答案 0 :(得分:0)
UIView *view = /*...*/;
CGContextRef ctx = /*...*/;
/* Shift center from UL corner to mid-x, mid-y. */
CGRect bounds = [view bounds];
CGFloat hx = bounds.size.width / 2.0;
CGFloat hy = bounds.size.height / 2.0;
CGContextTranslateCTM(ctx, hx, hy);
/* y still increases down, and x to the right. */
/* if you want y to increase up, then flip y: */
CGContextScaleCTM(ctx, 1.0/*sx*/, -1.0/*sy*/);
答案 1 :(得分:0)
默认情况下,(0,0)位于视图的左上角。要将此点移动到视图的中心,请修改其边界:
CGFloat width = self.bounds.size.width;
CGFloat height = self.bounds.size.height;
self.bounds = CGRectMake(-width/2.0, -height/2.0, width, height);
确保在视图大小发生变化时重复此计算。