drawRect方法在iOS7 / 8中得到不同的Rect值

时间:2015-12-11 09:04:42

标签: ios objective-c uikit

我在调用此方法的两个不同设备上遇到此问题

- (void)drawRect:(CGRect)rect {

    NSLog(@"%@", NSStringFromCGRect(rect));
    NSLog(@"F: %@", NSStringFromCGRect(self.frame));
    NSLog(@"B: %@", NSStringFromCGRect(self.bounds));

    [super drawRect:rect];
}

在iOS8输出中是:

{{-1.5, -3}, {74, 22.5}}
F: {{235, 63.5}, {70, 15}}
B: {{0, 0}, {70, 15}}

但是iOS7的输出是:

{{0, 0}, {70, 15}}
F: {{235, 63.5}, {70, 15}}
B: {{0, 0}, {70, 15}}

此标签的限制是: enter image description here

1 个答案:

答案 0 :(得分:0)

可能是因为状态栏。如果你想隐藏状态栏,那么这个或反之亦然

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>