如何反转 UIView?

发布于 2024-08-14 13:17:08 字数 574 浏览 5 评论 0原文

我正在使用 core-plot 库在我的 iPhone 应用程序上绘制条形图,当我尝试向图表添加标签或其他一些视图时出现问题,

实际上我添加的视图是垂直绘制的 invert 这样的........

代码就像

UILabel *lbl= [[UILabel alloc] initWithFrame:CGRectMake(250, 90, 70, 25)];
    [lbl setBackgroundColor:[UIColor redColor]];
    [lbl setText:@"HELLO"];
    [self.view addSubview:lbl];
    [lbl release];

我不敢玩核心图库。

那么还有其他方法可以把事情做好吗?我应该在添加视图之前进行转换吗?

如果这是解决方案,那么这将是昂贵的,因为我必须添加多个子视图。

希望大家都清楚我的问题。

I am using core-plot library to draw a bar-chart on my iPhone application and the problem arises when I try to add a label or some other views to the graph,

Actually the view I added is drawn vertically invert like this ........

The code is like

UILabel *lbl= [[UILabel alloc] initWithFrame:CGRectMake(250, 90, 70, 25)];
    [lbl setBackgroundColor:[UIColor redColor]];
    [lbl setText:@"HELLO"];
    [self.view addSubview:lbl];
    [lbl release];

I am not daring to play with core-plot library.

So is there any other way to do the things right? should I do a transform before adding the views?

If this is the solution then this will be costly because I have to add more than one subview.

Hoping my question is clear to everybody.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

兔姬 2024-08-21 13:17:08

嗯,看起来核心图视图是使用 CGAffineTransform 反转的。您的视图可能继承了其超级视图的反转。
其实做起来很简单,

lbl.transform = CGAffineTransformMakeScale(1,-1);

应该可以做到。
如果你必须多次执行,也许可以用诸如此类的东西来简化它

CGAffineTransform verticalFlip = CGAffineTransformMakeScale(1,-1);
lbl.transform = verticalFlip;
otherLbl.transform = verticalFlip;

......

x轴翻转将是CGAffineTransformMakeScale(-1,1);

Well, it looks like the core-plot view is inverted using a CGAffineTransform. Your view is probably inheriting the inversion from its superview.
It's actually quite simple to do,

lbl.transform = CGAffineTransformMakeScale(1,-1);

Should do the trick.
If you have to do it many times perhaps simplify it with something like,

CGAffineTransform verticalFlip = CGAffineTransformMakeScale(1,-1);
lbl.transform = verticalFlip;
otherLbl.transform = verticalFlip;

etc...

An x-axis flip would be CGAffineTransformMakeScale(-1,1);

何以心动 2024-08-21 13:17:08

为了避免猜测实际的变换值,您可以尝试使用 CGAffineTransformInvert 函数:

lbl.transform = CGAffineTransformInvert(self.view.transform);

To avoid guessing actual transform values you can try to use CGAffineTransformInvert function:

lbl.transform = CGAffineTransformInvert(self.view.transform);
柒七 2024-08-21 13:17:08

如果我们想要转换 3D 模型层,您需要按如下方式处理它,

Swift 5:

// To inverse the graph vertically
annotationGraph.transform = CATransform3DMakeAffineTransform(CGAffineTransform(scaleX: 1, y: -1))

否则您会收到这个,

无法将“CGAffineTransform”类型的值分配给“CATransform3D”类型

If we want to transform a layer which is 3D model you need to handle it as follows,

Swift 5:

// To inverse the graph vertically
annotationGraph.transform = CATransform3DMakeAffineTransform(CGAffineTransform(scaleX: 1, y: -1))

otherwise you would have receive this,

Cannot assign value of type 'CGAffineTransform' to type 'CATransform3D'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文