如何在通話期間將視圖放在綠色欄下方?

[英]How to position view below green bar during phone call?


How do I make my view appear below the green bar during a phone call? right now my app is being partially covered by the green bar during a phone call.

如何在通話期間讓我的視圖顯示在綠色欄下方?現在,我的應用程序在電話呼叫期間被綠色欄部分覆蓋。

4 个解决方案

#1


7  

If you're using Interface Builder, make sure your autoresize masks are set so that it resizes the views instead of just having them sit there in the same position. You can use the Toggle In-Call Status Bar option under Hardware in the Simulator to test it.

如果您正在使用Interface Builder,請確保設置自動調整大小的蒙版,以便調整視圖大小,而不是讓它們位於相同位置。您可以使用模擬器中硬件下的Toggle In-Call Status Bar選項來測試它。

If you're not using IB, you can set up the autoresize masks in code.

如果您不使用IB,則可以在代碼中設置自動調整大小的掩碼。

If you're not using views, you'll need to resize your graphics when you get the appropriate notifications.

如果您沒有使用視圖,則需要在收到相應的通知時調整圖形大小。

#2


23  

You can find out when this is about to happen using the following UIApplicationDelegate methods:

您可以使用以下UIApplicationDelegate方法找出何時發生這種情況:

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame {
    NSLog(@"willChangeStatusBarFrame : newSize %f, %f", newStatusBarFrame.size.width, newStatusBarFrame.size.height);
}

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)newStatusBarFrame {
    NSLog(@"didChangeStatusBarFrame : newSize %f, %f", newStatusBarFrame.size.width, newStatusBarFrame.size.height);
}

Alternatively, you can register for a notification in your UIViewController subclass:

或者,您可以在UIViewController子類中注冊通知:

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameWillChange:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
}

- (void)statusBarFrameWillChange:(NSNotification*)notification {
    NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
    CGRect newFrame;
    [rectValue getValue:&newFrame];
    NSLog(@"statusBarFrameWillChange: newSize %f, %f", newFrame.size.width, newFrame.size.height);
    // Move your view here ...
}

- (void)statusBarFrameChanged:(NSNotification*)notification {
    NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
    CGRect oldFrame;
    [rectValue getValue:&oldFrame];
    NSLog(@"statusBarFrameChanged: oldSize %f, %f", oldFrame.size.width, oldFrame.size.height);
    // ... or here, whichever makes the most sense for your app.
}

#3


5  

Note that the suggestions above also fire when the device is rotated. If you just want to find when the status bar has grown in height due to an incoming/ongoing phone call. I found the following code to work:

請注意,上述建議也會在設備旋轉時觸發。如果您只想查找狀態欄由於傳入/正在進行的電話呼叫而在高度增加的時間。我找到了以下代碼:

AppDelegate.m

AppDelegate.m

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
    float adjustment = 0;

    if ([UIApplication sharedApplication].statusBarFrame.size.height == 40) 
    {
        adjustment = -20;
    }
    else if  ([UIApplication sharedApplication].statusBarFrame.size.height == 20 && oldStatusBarFrame.size.height == 40)
    {
        adjustment = 20;
    }
    else 
    {
        return;
    }

    CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:duration];

    {YOUR VIEW Controller - remove .view if a view}.view.frame = CGRectMake({YOUR VIEW Controller}.view.frame.origin.x, {YOUR VIEW Controller}.view.frame.origin.y + adjustment, {YOUR VIEW Controller}.view.frame.size.width, {YOUR VIEW Controller}.view.frame.size.height);

    [UIView commitAnimations];
}

#4


0  

Idem with a Tab Bar App and iOS6/7, thanks to user1208489's answer.

感謝user1208489的回答,同意使用Tab Bar應用程序和iOS6 / 7。

Values are completely different and weird for each iOS. ;oP

每個iOS的值都完全不同且很奇怪。 ;業務

mainAppDelegate.m

mainAppDelegate.m

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
float vue = 0;
float barre = 0;
float hauteur = 0;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 // pour Xcode5/SDK7

if ([UIApplication sharedApplication].statusBarFrame.size.height == 40)
{
    vue = -20;
    barre = +20;
}
else
    if ([UIApplication sharedApplication].statusBarFrame.size.height == 20 && oldStatusBarFrame.size.height == 40)
    {
        vue = 0;
        barre = -20;
    }
    else return;

#else // pour Xcode4/SDK6

if ([UIApplication sharedApplication].statusBarFrame.size.height == 40)
{
    vue = +20;
    hauteur = 1;
    barre = -1-20;
}
else
    if ([UIApplication sharedApplication].statusBarFrame.size.height == 20 && oldStatusBarFrame.size.height == 40)
    {
        vue = -20;
        hauteur = -1;
        barre = +1+20;
    }
    else return;

#endif

CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];

self.tabBarController.view.frame = CGRectMake(self.tabBarController.view.frame.origin.x, self.tabBarController.view.frame.origin.y + vue, self.tabBarController.view.frame.size.width, self.tabBarController.view.frame.size.height+hauteur);
self.tabBarController.tabBar.frame = CGRectMake(self.tabBarController.tabBar.frame.origin.x, self.tabBarController.tabBar.frame.origin.y + barre, self.tabBarController.tabBar.frame.size.width, self.tabBarController.tabBar.frame.size.height);

[UIView commitAnimations];
}

Tested on iPhone 4S 7.0.4 (11B554a) with Xcode 4.6.3 (4H1503) and Xcode 5.0.2 (5A3005).

使用Xcode 4.6.3(4H1503)和Xcode 5.0.2(5A3005)在iPhone 4S 7.0.4(11B554a)上進行測試。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/07/21/72f241082787622611d8d1ec86a6b5cf.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com