IOS视图转换修改帧? [英] IOS view transformation modifies frame?

查看:77
本文介绍了IOS视图转换修改帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,我在drawRect中做一些特定的绘图。这些图纸是动态的,基于视图的宽度和高度。然后,包含它的视图对其应用旋转变换。然而,这种转换似乎调整了我的视图框架的值,这会影响我在drawRect中的绘图。

I have a view in which I am doing some specific drawings in drawRect. These drawings are dynamic and are based on the view's width and height. Then, the view which contains it applies a rotation transformation to it. However this transformation seems to adjust the values for my view's frame which impacts my drawing in drawRect.

NSLog(@之前:%f,%f,%f,%f,button.frame.origin.x,button.frame.origin.y, button.frame.size.width,button.frame.size.height);

NSLog(@"before:%f,%f,%f,%f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.frame.size.height);

    CGAffineTransform currentTransform = button.transform;
    CGAffineTransform transformRotate = CGAffineTransformMakeRotation(degreesToRadians);
    button.transform = transformRotate;

    NSLog(@"after:%f,%f,%f,%f",button.frame.origin.x,button.frame.origin.y,button.frame.size.width,button.frame.size.height);

以下是输出:

之前:50.000000,100.000000,150.000000,50.000000
之后:65.849365,47.548096,118.301262,154.903809

before:50.000000,100.000000,150.000000,50.000000 after:65.849365,47.548096,118.301262,154.903809

这是正确的行为还是我错误地应用了转换?

Is this correct behaviour or am I applying the transformation incorrectly?

推荐答案

请参阅 UIView的框架属性;

框架

frame


框架矩形,用于描述
中视图的位置和大小它的superview的坐标系。

The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.



@property(nonatomic) CGRect frame

警告


如果transform属性不是identity变换,则
的值未定义此属性d因此应该被忽略。

If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.






尽管有这样的警告,事情仍按预期工作。一旦应用了变换(其他身份),帧通常会生成原始视图的投影矩形。
但是,如果您真的想要了解应用转换的框架并使用 CGRectApplyAffineTransform 正确获取它。

这篇关于IOS视图转换修改帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆