ios6-7之後用戶開熱點後的屏幕適配

// 排版時,注意logical coordinate space和device coordinate space的區別,注意frame和bounds的區別!工具

 

- (void)loadViewspa

{接口

    // ...get

 

    // 計算Custom Content View的Rect
    if (!_supportFullScreen)
    {
        CGFloat contentSatrtY = 0;
        
        if (IS_HOTSPOT_CONNECTED) { // iPhone4(s)-iOS6/iOS7屏幕座標系下:hostView.frame={{0, 40}, {320, 440}}/{{0, 20}, {320, 460}}
            contentSatrtY = STATUS_AND_NAV_BAR_HEIGHT; // 84
            if (SYSTEM_VERSION >= 7.0) { // 若是設置了edgesForExtendedLayout=UIRectEdgeNone
                contentSatrtY -= HOTSPOT_STATUSBAR_HEIGHT;// 64(有熱點欄時,會自動下移20)
            }
        } else { // iPhone4(s)-iOS6/iOS7屏幕座標系下:hostView.frame={{0, 20}, {320, 460}}/{{0, 0}, {320, 480}}
            contentSatrtY = NORMAL_STATUS_AND_NAV_BAR_HEIGHT; // 64
        }
        
        // contentSatrtY基於UIViewController.view所在的屏幕座標系進行排版
        contentRect = CGRectMake(0, contentSatrtY, hostView.width, SCREEN_HEIGHT-STATUS_AND_NAV_BAR_HEIGHT-TOOLBAR_HEIGHT);
    }
    else // 針對iOS6/7分別配置了wantsFullScreenLayout=YES/edgesForExtendedLayout=UIRectEdgeAll,全屏隱藏狀態欄(包括熱點欄)、導航欄和工具欄以後高度爲SCREEN_HEIGHT
    {
        contentRect = CGRectMake(0, 0, hostView.width, hostView.height);
    }io

 

    // ...class

}配置

// 若有必要,需監聽系統狀態欄變動通知:UIApplicationWillChangeStatusBarFrameNotificationobject

- (void)handleUIApplicationWillChangeStatusBarFrameNotification:(NSNotification*)notification
{
    CGRect newStatusBarFrame = [(NSValue*)[notification.userInfo objectForKey:UIApplicationStatusBarFrameUserInfoKey] CGRectValue];遍歷

    // 根據系統狀態欄高判斷熱點欄的變更
    BOOL bPersonalHotspotConnected = (CGRectGetHeight(newStatusBarFrame)==(SYS_STATUSBAR_HEIGHT+HOTSPOT_STATUSBAR_HEIGHT)?YES:NO);

    CGPoint newCenter = CGPointZero;
    CGFloat OffsetY = bPersonalHotspotConnected?+HOTSPOT_STATUSBAR_HEIGHT:-HOTSPOT_STATUSBAR_HEIGHT;
    if (SYSTEM_VERSION >= 7.0) { // 即便設置了extendedLayoutIncludesOpaqueBars=NO/edgesForExtendedLayout=UIRectEdgeNone,對沒有自動調整的部分View作必要的手動調整
        newCenter = self.someSubView.center;
        newCenter.y += OffsetY;
        self.someSubView.center = newCenter;
    } else { // Custom Content對應的view總體調整
        newCenter = self.contentView.center;
        newCenter.y += OffsetY;
        self.contentView.center = newCenter; // contentView爲Custom Content對應的view
    }
}next

@end

 

 

.iPhone/iOS我的熱點的interface

iPhone開啓我的熱點(橋接上網)時,會多出bridge接口。

 

iPhone5s/iOS8.2開啓我的熱點時,遍歷可發現多出3個活躍的bridge100接口(IFF_UP),sa_family分別是AF_LINK(18)、AF_INET6(30)、AF_INET(2)。

遍歷interface的代碼片斷以下:

 

struct ifaddrs *interfaces = nil;

 

if(!getifaddrs(&interfaces))

 

{

 

    for(structifaddrs *interface = interfaces; interface; interface = interface->ifa_next) {

 

            if ((interface->ifa_flags&IFF_UP) ==IFF_UP) {

 

                log_notice("ifa_name : %s, ifa_addr->sa_family : %d", interface->ifa_name, interface->ifa_addr->sa_family);

 

            }

 

       }

 

}

 

 

 

if (interfaces) {

 

    freeifaddrs(interfaces);

 

    interfaces = NULL;

 

}

相關文章
相關標籤/搜索