UILabel 与基于 Orientation 的 CGAffineTransformMakeRotation? (ARC、故事板、LLDB)

发布于 2024-12-31 22:40:33 字数 637 浏览 1 评论 0原文

我以前曾问过这个问题一次,但关注度为 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));
}

I had asked this question once before but has had 0 attention and the person helping me has not responded in weeks, so please forgive me but I still do need help.

Im working with CGAffineTransformMakeRotation to flip a UILabel 180 degrees, I want the rotation based on UIOrientationPortrait and UIOrientationPortraitUpsideDown. I get 1/2 the result: when users flip to upside down (from portrait) the label transforms 180 and turns upside down as well (still facing the home button [Important])

BUT

when I rotate it back to Portrait the label stays in the flipped rotation state and does not stay with the home button. Thats what I need help with....

Here is the code i have:

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

...

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

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

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

发布评论

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

评论(2

笑叹一世浮沉 2025-01-07 22:40:33

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

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

这样,当设备颠倒时,它将上下旋转标签,而当设备处于纵向时,它将恢复正常方向。

You are rotating it upside down no matter what the orientation is. If you want it to rotate differently depending on the orientation, you have to do something like this:

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

That way, it will rotate the label upside down when the device is upside down and it will return it back to normal when the device is on portrait orientation.

ヤ经典坏疍 2025-01-07 22:40:33

我认为您想要打开 toInterfaceOrientation,如果方向为 UIInterfaceOrientationPortraitUpsideDown 则按照上面的方式设置变换,当方向为 时设置为 CGAffineTransformIdentity UIInterfaceOrientationPortrait。 (这假设您不允许旋转到其他方向。)

I think you want to switch on toInterfaceOrientation, setting the transform as you have above if the orientation is UIInterfaceOrientationPortraitUpsideDown and to CGAffineTransformIdentity when it's UIInterfaceOrientationPortrait. (This assumes you don't allow rotations to the other orientations.)

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