【问题标题】:UILabel with CGAffineTransformMakeRotation based on Orientation? (ARC, Storyboard, LLDB)基于方向的带有 CGAffineTransformMakeRotation 的 UILabel? (ARC,故事板,LLDB)
【发布时间】:2012-01-28 01:00:32
【问题描述】:

我曾经问过这个问题,但关注度为 0,帮助我的人已经数周没有回复,所以请原谅我,但我仍然需要帮助。

我正在使用 CGAffineTransformMakeRotation 将 UILabel 翻转 180 度,我想要基于 UIOrientationPortrait 和 UIOrientationPortraitUpsideDown 的旋转。我得到了 1/2 的结果:当用户翻转到倒置(从纵向)时,标签会转换 180 并且也会倒置(仍然面向主页按钮 [重要])

但是

当我将其旋转回纵向时,标签会保持翻转旋转状态,并且不会与主页按钮保持一致。这就是我需要帮助的......

这是我的代码:

#define degreesToRadian(x) (M_PI * (x) / 180.0)

...

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    TranslateLabel.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
}

【问题讨论】:

    标签: iphone ipad xcode4.2 uiimagepickercontroller mfmailcomposeviewcontroller


    【解决方案1】:

    无论方向如何,您都会将其倒置。如果您希望它根据方向以不同方式旋转,则必须执行以下操作:

    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
      switch(toInterfaceOrientation){
        case UIInterfaceOrientationPortrait:
          TranslateLabel.transform = CGAffineTransformIdentity;
          break;
        case UIInterfaceOrientationPortraitUpsideDown:
          TranslateLabel.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
          break;
      }
    }
    

    这样,当设备倒置时,它会将标签倒置,当设备处于纵向时,它会恢复正常。

    【讨论】:

    • 这行得通,但我必须添加 case UIInterfaceOrientationLandscapeLeft: break;案例 UIInterfaceOrientationLandscapeRight: break;所以枚举错误就会消失。
    • 您也可以添加一个默认值,如果以上都没有发生,它将执行,因此您不必添加每个案例。
    【解决方案2】:

    我想你想打开toInterfaceOrientation,如果方向是UIInterfaceOrientationPortraitUpsideDown,则设置转换,如果方向是CGAffineTransformIdentity,则设置为CGAffineTransformIdentity,当它是UIInterfaceOrientationPortrait。 (这假设您不允许旋转到其他方向。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-07
      • 2016-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多