XCode在呼叫状态栏中更改视图

时间:2015-03-24 12:06:38

标签: ios objective-c xcode uiview uiviewcontroller

我在XCode中创建了一个Viewcontroller,一切正常。当有电话呼叫时,呼叫状态栏中的按钮会按下视图底部的按钮" DOWN"由于我在通话期间无法点击按钮。

我想知道即使拨打电话,如何将按钮保持在底部,同一位置。我尝试了几种方法对我没用。

- (void)statusBarFrameWillChange:(NSNotification*)notification {
    NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
    CGRect newFrame;
    [rectValue getValue:&newFrame];
    CGRect fixedFrame = bottomBar.frame;
    fixedFrame.origin.y = fixedFrame.origin.y - newFrame.size.height; //Keep the Y position as it is
    bottomBar.frame = fixedFrame;
    NSLog(@"statusBarFrameWillChange: newSize %f, %f, %f", fixedFrame.origin.y, newFrame.size.width, newFrame.size.height);
}

- (void)statusBarFrameChanged:(NSNotification*)notification {
    NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
    CGRect oldFrame;
    [rectValue getValue:&oldFrame];
    CGRect fixedFrame = bottomBar.frame;
    fixedFrame.origin.y = fixedFrame.origin.y + oldFrame.size.height;
    bottomBar.frame = fixedFrame;
    NSLog(@"statusBarFrameChanged: oldSize %f, %f, %f", fixedFrame.origin.y, oldFrame.size.width, oldFrame.size.height);
}

1 个答案:

答案 0 :(得分:0)

使用自动布局,请务必设置Bottom Space约束:

enter image description here