iOS开发中遇到的问题

来源:互联网 发布:mac转码软件 编辑:程序博客网 时间:2024/05/14 15:46

在项目开发中,自己遇到一些问题及解决方法,不断更新中。

(1)UINavigationBarUITabBar上有一条横线,是ShadowImage,默认是黑色的。在项目开发中,可以改变其图片和颜色。在下图个人热点图中可以看到导航栏下面的黑线。

[self.navigationController.navigationBar  setShadowImage:[UIImage imageWithColor:MyColor]];

(2) statusBar默认的高度是20.0f,在使用微信或者QQ通话,热点等功能进入后台时,statusBar的高度会变为40.0f,下方的布局也会发生变化,在此要根据statusBar的变化调整布局,设置监听监听其变化。

打开热点时<code>statusBar</code>高度变化

监听对象为UIApplicationDidChangeStatusBarFrameNotification

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(statusBarFrameWillChange:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];//添加监听[[NSNotificationCenter defaultCenter]removeObserver:self name:UIApplicationDidChangeStatusBarFrameNotification object:nil];//移除监听

当前statusBar的高度也是可以获取的:

NSValue *rectValue = [notification.userInfo objectForKey:UIApplicationStatusBarFrameUserInfoKey];CGRect statusRect = [rectValue CGRectValue];CGRect statusFrame = [self.view convertRect:statusRect fromView:[[UIApplication sharedApplication]keyWindow]];CGFloat statusHeight = statusFrame.size.height;

(3)在iPad开发时,使用iOS 9系统会出现tableviewCell的位置变化,在开发中默认与右侧是15个像素,可是现在明显大的多,这是因为在iOS 9后tableview的一个属性发生了变化。

tableviewCell位置变化

需要调整

tableView.cellLayoutMarginsFollowReadableWidth = NO;

补充,因为方法是iOS9之后出现的,因此在调用时需要判断系统是否大于9.0

if([UIDevice currentDevice].systemVersion.floatValue >= 9.0){    tableView.cellLayoutMarginsFollowReadableWidth = NO;}

(4)在做直播功能模块,使用到 弹幕 的功能(弹幕使用第三方库BarrageRenderer),弹幕为横屏自动开启,竖屏时关闭。在测试用发现弹幕有时开有时关,最终发现在屏幕横放时无法显示。原因是设置方法出现错误。

通过[UIDevice currentDevice].orientation 的状态判断横竖屏会出现错误,因为其枚举类型是UIDeviceOrientation,在查看其枚举类型时会发现其除了Portrait LandscapeLeft LandscapeRight PortraitUpsideDown外还有FaceUp FaceDown两个状态,忽略对其的设置会产生影响。

UIDeviceOrientation 枚举

typedef NS_ENUM(NSInteger, UIDeviceOrientation) {    UIDeviceOrientationUnknown,    UIDeviceOrientationPortrait,            // Device oriented vertically, home button on the bottom    UIDeviceOrientationPortraitUpsideDown,  // Device oriented vertically, home button on the top    UIDeviceOrientationLandscapeLeft,       // Device oriented horizontally, home button on the right    UIDeviceOrientationLandscapeRight,      // Device oriented horizontally, home button on the left    UIDeviceOrientationFaceUp,              // Device oriented flat, face up    UIDeviceOrientationFaceDown             // Device oriented flat, face down} __TVOS_PROHIBITED;

在对其使用时还可以将其转换成UIInterfaceOrientation,因为后者只有常见的几种类型。

UIDeviceOrientation orientation             = [UIDevice currentDevice].orientation;UIInterfaceOrientation interfaceOrientation = (UIInterfaceOrientation)orientation;

UIInterfaceOrientation枚举

typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {    UIInterfaceOrientationUnknown            = UIDeviceOrientationUnknown,    UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,    UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,    UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,    UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft} __TVOS_PROHIBITED;

另外在横竖屏切换时我们会对屏幕的状态做监听,通常监听的是UIDeviceOrientationDidChangeNotification,监听得到的结果是UIDeviceOrientation,也可以监听UIApplicationDidChangeStatusBarFrameNotification,得到UIInterfaceOrientation。当然UIApplicationDidChangeStatusBarFrameNotification也可以监听热点等事件中出现的问题,如问题2.

更多问题后续补充,欢迎探讨指正

0 0
原创粉丝点击