ios6-7以后用户开热点后的屏幕适配

// 排版时,注意logical coordinate space和device coordinate space的区别,注意frame和bounds的区别!

- (void)loadView

{

// ...

// 计算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);
    }

// ...

}

// 如有必要,需监听系统状态栏变更通知:UIApplicationWillChangeStatusBarFrameNotification

- (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
    }
}

@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;

}

上一篇:redis中关于使用string类型还是hash类型


下一篇:ArrayList list = new ArrayList()在这个泛型为Integer的ArrayList中存放一个String类型的对象