【问题标题】:Can 2D and 3D transforms be applied to iOS controls?可以将 2D 和 3D 变换应用于 iOS 控件吗?
【发布时间】:2013-09-14 19:52:36
【问题描述】:

之前从未真正使用 iOS 进行过开发,我正在研究使用标准 iOS 控件(如文本字段、列表等)的可能性,并想知道可以对它们应用哪些变换。

这些标准控件是否支持 2D 变换,例如缩放、平移和旋转? 这些标准控件是否还支持包含 z 轴的 3D 变换,例如缩放、平移和旋转?

如果任何一个问题的答案都是肯定的,那么存在什么“级别”的支持?例如对于一个文本字段,如果我在 3D 坐标空间中对其进行转换,我仍然可以在其中输入文本吗?

【问题讨论】:

    标签: iphone ios ipad 3d 2d


    【解决方案1】:

    是的,而且很多。 UITextField 例如继承自 UIControl,继承自 UIView。这意味着您可以通过其 transform 属性直接访问视图的 transform 属性:

    [myTextField setTransform:CGAffineTransformMake(a, b, c, d, x, y)];
    

    或者对于 3D 支持,您可以访问视图层的变换属性以应用 CATransform3D:

    [myTextField.layer setTransform:CATransform3DRotate(trans, theta, x, y, z)];
    

    CATransform3D 定义如下,正如@Xman 指出的那样,您需要使用#import <QuartzCore/QuartzCore.h> 导入 QuartzCore 框架,并在构建阶段链接它。

    struct CATransform3D
    {
        CGFloat m11, m12, m13, m14;
        CGFloat m21, m22, m23, m24;
        CGFloat m31, m32, m33, m34;
        CGFloat m41, m42, m43, m44;
    };
    typedef struct CATransform3D CATransform3D;
    

    在这两种情况下,您仍然可以在应用转换后与文本字段进行交互。

    更多信息可以在Apple's documentation找到。

    【讨论】:

    • @FelixBembrick 当然,如果我的回答有帮助,别忘了标记为正确。
    • 好的,为了清楚起见,即使在文本字段已转换为 3D 坐标以使其显示在立方体的表面上之后,是否仍然可以输入文本?
    • 添加了相关文档的链接,以便人们阅读更多内容
    • @FelixBembrick 抱歉回复晚了,是的。
    【解决方案2】:

    也检查CATransform3D

    CATransform3D yourTransform = CATransform3DIdentity;
    yourTransform.m34 = 1.0 / -500;
    
    //You can rotate the component in any angle around x,y,z axis using following line.
    //Below line will rotate the component in 60 degree around y-axis.
    yourTransform = CATransform3DRotate(yourTransform, DEGREES_TO_RADIANS(60), 0.0f, 1.0f, 0.0f);      //#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)
    
    //You can even translate the component along x,y,z axis
    //Below line will translate component by 50 on y-axis
    yourTransform = CATransform3DTranslate(yourTransform, 0, 50, 0);
    
    //apply transform to component
    yourComponent.layer.transform = yourTransform;
    

    别忘了导入

    #import <QuartzCore/QuartzCore.h>
    

    希望这会对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多