首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向windows中添加的iOS8视图的轮转问题

向windows中添加的iOS8视图的轮转问题
EN

Stack Overflow用户
提问于 2014-09-05 11:29:00
回答 2查看 6K关注 0票数 6

我已经为视图旋转创建了类别,并在控制器视图和窗口上添加了视图(用于显示自定义指示符)。我的代码在xCode 5.X和xCode6-beta6中运行良好,可以达到7.X。但IOS 8测试版并不合适。它似乎不像旧版的ios 8测试版那样适用于windows轮转。

你能建议我..。提前谢谢。

我的代码看起来像

代码语言:javascript
复制
- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration {
 if(!self.isIpad)
{

    [menu.view rotateViewToOrientation:newStatusBarOrientation animated:YES];
    if(newStatusBarOrientation==UIInterfaceOrientationPortrait || newStatusBarOrientation==UIInterfaceOrientationPortraitUpsideDown)
    {
        if (IS_IPHONE_5) {
            menu.view.frame= CGRectMake(0, 518, 320, 50);
        } else {
            menu.view.frame= CGRectMake(0, 430, 320, 50);
        }

    }  else if(newStatusBarOrientation==UIInterfaceOrientationLandscapeLeft) {

        if (IS_IPHONE_5) {
            menu.view.frame= CGRectMake(270,0,50,568);
        } else {
            menu.view.frame= CGRectMake(270,0,50,480);
        }

    } else {

        if (IS_IPHONE_5) {
            menu.view.frame= CGRectMake(0,0,50,568);
        } else {
            menu.view.frame= CGRectMake(0,0,50,480);
        }
    }
    [menu reloadMenu];
  }
}


//Method of Menu Class for orientation change setup
- (void)rotateViewToOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated {
CGPoint center = self.center;
CGRect bounds = self.bounds;
CGAffineTransform transform = CGAffineTransformIdentity;
int intOri=orientation;
switch (intOri) {
    case UIInterfaceOrientationPortraitUpsideDown:
        transform = CGAffineTransformMakeRotation(M_PI);
        break;
    case UIInterfaceOrientationLandscapeLeft:
        transform = CGAffineTransformMakeRotation(-M_PI_2);
        break;
    case UIInterfaceOrientationLandscapeRight:
        transform = CGAffineTransformMakeRotation(M_PI_2);
        break;
    case UIInterfaceOrientationPortrait:
        transform = CGAffineTransformMakeRotation(0);
        break;

}
if (animated) {
    [UIView beginAnimations:nil context:nil];
}
self.transform = transform;
bounds = CGRectApplyAffineTransform(bounds, transform);
self.bounds = CGRectMake(0, 0, bounds.size.width, bounds.size.height);
self.center = center;
 if (animated) {
    [UIView commitAnimations];
 }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-09-06 10:00:59

我试过很多修复方法..。它和补丁一起工作,比如

代码语言:javascript
复制
{
[self.window setBounds:temp];
[menu.view setFrame:CGRectMake(0, self.window.frame.size.height-50, self.window.frame.size.width, 50)];
[menu.view removeFromSuperview];
[self.window addSubview:menu.view];
[self.window makeKeyAndVisible];
}

对于所有类型的设备模式,对于CGAffineTransformMakeRotation,对于ios 8,重新设定角度到0度。

这不是一个正确的解决方案,我知道,但我没有任何替代的方式,所以等待一个好的答案。

票数 7
EN

Stack Overflow用户

发布于 2014-09-29 23:02:30

在我的例子中,简单地将所有方向的旋转角设置为0就解决了这个问题。在iOS 8之前,UIWindow坐标一直是面向肖像的,所以你必须自己处理旋转。这在iOS 8中不再是必要的。至于为什么要将UIViews添加到UIWindow中,我这样做是因为我想在其他所有东西上显示警报,而不管当前的视图层次结构如何。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25684892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档