【问题标题】:Ipad/Iphone - Rotation in UIView with images an allIpad/Iphone - 在 UIView 中旋转图像和全部
【发布时间】:2010-12-07 05:54:55
【问题描述】:

如何旋转充满内容的 UIView。我在 UIViews 的旋转中遇到问题。谁能帮我吗???请给我一些喜欢的逐步示例。

【问题讨论】:

  • 您说的是哪种类型的轮换?方向改变?
  • 旋转当我们旋转 Iphone/Ipad 横向和纵​​向时,我遇到了界面问题,它显示了不同的行为。如果用户旋转它的 ipad/iphone 视图应该根据旋转改变。

标签: iphone ipad animation core-graphics rotation


【解决方案1】:

这很简单:

myUIView.transform = CGAffineTransformMakeRotation(M_PI * 0.5); 

这将使整个内容向右旋转 90 度,内容和所有内容。 CGAffineTransformMakeRotation 的参数是弧度...

【讨论】:

  • 非常感谢,但我仍然在图像旋转时遇到问题,它不能正确显示,视图移动正常。??
  • 谢谢安迪,这帮助很大!
  • 为了安全起见,我也会在您的窗口上设置黑色背景色。我在旋转并将窗口背景更改为黑色时遇到了白线问题。
【解决方案2】:

您好,非常感谢您的回复。与旋转相关的东西已经解决,但在横向模式下我仍然没有什么问题我正在使用此代码为两个 UIView 设置动画,但在横向模式下,一个视图没有出现,我想要一个理想的解决方案。

我目前正在使用的轮换代码...

- (void)viewDidLoad 
{

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)   name:UIDeviceOrientationDidChangeNotification object:nil];

}


- (void)didRotate:(NSNotification *)notification {

    UIDeviceOrientation orientation = [[notification object] orientation];

    if (orientation == UIDeviceOrientationLandscapeLeft) 
    {

        CGRect contentRect = CGRectMake(0,0, 1024, 748);
        self.view.bounds = contentRect;
        [self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
    } 
    else if (orientation == UIDeviceOrientationLandscapeRight) 
    {

        CGRect contentRect = CGRectMake(0,0, 1024, 748);
        self.view.bounds = contentRect; 


        [self.view setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
    }

    else if (orientation == UIDeviceOrientationPortraitUpsideDown) 
    {

        CGRect contentRect = CGRectMake(0,0, 768, 1024);
        self.view.bounds = contentRect;
        [self.view setTransform:CGAffineTransformMakeRotation(M_PI)];
    } 
    else if (orientation == UIDeviceOrientationPortrait) {

        CGRect contentRect = CGRectMake(0,0, 768, 1024);
        self.view.bounds = contentRect;
        [self.view setTransform:CGAffineTransformMakeRotation(0.0)];
    }


}

UIView 执行代码。

self.loginView.hidden=NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
self.AcTypeView.transform=CGAffineTransformMakeTranslation(0, 493);
[UIView commitAnimations];



[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];

self.loginView.transform=CGAffineTransformMakeTranslation(0, -700);
[UIView commitAnimations];




Thanks!!!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多