码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2016-08-13 15:46:20      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

// 排版时,注意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;

 

}

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

标签:

原文地址:http://www.cnblogs.com/haohao-developer/p/5768065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!