Ipad/Iphone - UIView 中的图像旋转

发布于 2024-10-06 12:42:11 字数 67 浏览 3 评论 0原文

如何旋转充满内容的 UIView。我在 UIView 旋转方面遇到问题。有人可以帮帮我吗???请给我一些类似的逐步示例。

How rotate UIView with full of contents. I am getting problem in rotation of UIViews. Can any one help me out??? please give me some like with step by step example.

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

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

发布评论

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

评论(2

别在捏我脸啦 2024-10-13 12:42:11

这很简单:

myUIView.transform = CGAffineTransformMakeRotation(M_PI * 0.5); 

这会将整个事情向右转 90 度,包括内容在内。
CGAffineTransformMakeRotation 的参数以弧度为单位...

It's pretty easy:

myUIView.transform = CGAffineTransformMakeRotation(M_PI * 0.5); 

That will turn the whole thing 90 degrees to the right, contents and all.
The argument to CGAffineTransformMakeRotation is in radians...

嘿哥们儿 2024-10-13 12:42:11

嘿,非常感谢您的回复。与旋转相关的问题已解决,但我在横向模式下仍然遇到一些问题,我使用此代码为两个 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!!!!

Hey thanks a lot for your response. Stuff which are related to rotation are solved but still i have few problems in Landscape mode i am using this code to animate Two UIViews but in Landscape Mode One view is not appearing i want an ideal solution for this.

Rotation Code which i am currently using...

- (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 amination code.

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