UIView 的边界和帧大小

Bounds and Frame Size of a UIView

我需要一些帮助来设置 UIView 的边界和框架,我通过将边界更改为 "0.0f、0.0f、1920.0f、1080.0 将其更改为 "full screen mode" f,行得通,我遇到的问题是当我需要将 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));

            }

尝试使用 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 ).

UIView 的框架是一个矩形,表示为相对于它所包含的 superview 的位置 (x,y) 和大小 (width,height)。

因此,frame 将帮助您在 superview 中调整视图。

谢谢