UIView的界限和框架大小

时间:2016-01-20 03:22:40

标签: ios objective-c uiview tvos bounds

我需要一些帮助来设置UIView的边界和框架,我将其更改为"全屏模式"通过将边界更改为" 0.0f,0.0f,1920.0f,1080.0f" ,这是有效的,我遇到的问题是当我需要撤消UIView时回到原始边界和框架大小,但我在设置它时遇到了麻烦。我可以帮忙吗?

CGRect rect = self.glView.frame;

            if (!CGRectEqualToRect(self.view.frame, rect))
            {
                NSLog(@"Switching to Full Screen now...");

                UIView *image = [_avplayController drawableView];

                image.frame =  CGRectMake(0.0f, 0.0f, 1920.0f, 1080.0f);

                self.glView.frame = image.frame;

            }
            else
            {
                NSLog(@"Switching to Normal Screen...");


                NSLog(@"Old Frame %@", NSStringFromCGRect(self.glView.frame));
                NSLog(@"Old Center %@", NSStringFromCGPoint(self.glView.center));

                // New Bounds and Frame size
                CGRect frame = self.glView.bounds;
                frame.size.height = 927.0f;
                frame.size.width = 619.0f;
                frame.origin.x = 931.0f;
                frame.origin.y = 65.0f;
                self.glView.bounds = frame;

                NSLog(@"New Frame %@", NSStringFromCGRect(self.glView.frame));
                NSLog(@"New Center %@", NSStringFromCGPoint(self.glView.center));

            }

1 个答案:

答案 0 :(得分:2)

尝试使用Frame代替Bounds

CGRect frame = self.glView.frame;
frame.size.height = 927.0f;
frame.size.width = 619.0f;
frame.origin.x = 931.0f;
frame.origin.y = 65.0f;
self.glView.frame = frame;

UIView的边界是矩形,表示为相对于其自己的坐标系(0,0)的位置(x,y)和大小(宽度,高度)。

UIView的框架是矩形,表示为相对于其中包含的 superview 的位置(x,y)和大小(宽度,高度)。

因此,框架将帮助您在超级视图中调整视图。

由于