iOS小技能:iOS中点与像素的关系 (retina 屏幕下的点= 像素/2)

网友投稿 266 2022-09-20

iOS小技能:iOS中点与像素的关系 (retina 屏幕下的点= 像素/2)

引言

提交app store的时候 需要一张1024*1024的如果不设置这两种的尺寸启动页的话,在4英寸、3.5英寸的设备上展示不了启动页,app 的高度也默认都是矮的960px.**

注意@3x 提供给开发的px 为12422208 ,但真实的px 是10801920,系统API会自动进行等比例缩小;

I iOS中点与像素有什么关系?

点是iOS中标准的坐标体系。它就是iOS中的虚拟像素,也被称为逻辑像素。

​​在标准设备中,一个点就是一个像素,但是在Ratina屏幕上,一个点等于2×2个像素。​​iOS用点作为屏幕的坐标测算体系就是为了在Retina设备和普通设备上能有一致的视觉效果。 2. 像素是图片分辨率的尺寸单位。物理像素坐标并不会用于屏幕布局,但是仍然和图片有相对关系。

​​retina 屏幕下的点= 像素/2。​​

II 图片使用的相关注意事项

2.1 推荐使用png格式

png: 常常放置于Assets.xcassets目录中,作为控件的背景图片。

压缩 较高,无损压缩,解压效率高,对CPU消耗少

jpg, 常常放置于Supporting Files目录

1)压缩比 比较高,通常用于照片、网页2)属于有损压缩(噪点noise)3)解压时对cpu 消耗大--意味着,慢、费电

2.2 关于图像的实例化

方式一:有缓存加载图片

UIImage *)imageNamed:(NSString *)name 系统推荐使用的方法,但图像实例化之后的对象释放由系统负责。// [arrayImage addObject: [UIImage imageNamed:pictureNamePrefix]];//参数为图片名称,png 格式的可以不加扩展名

方式二:无缓存方式加载图片(提示、如果放置于Assets.xcassets目录中的图片不能使用imageWithContentsOfFile:path进行加载;只能使用imageName进行加载,即内存由系统负责了)

//方式二:无缓存方式加载图片-指定扩展名// NSArray *arrayPicture = [pictureNamePrefix componentsSeparatedByString:@"."];//从字符中分隔成2个元素的数组(图片名+扩展名)// NSString *path = [[NSBundle mainBundle] pathForResource:arrayPicture[0] ofType: arrayPicture[1]];//获取图片的全路径 //方式二:无缓存方式加载图片-不指定扩展名 NSString *path = [[NSBundle mainBundle] pathForResource:pictureNamePrefix ofType:nil]; [arrayImage addObject:[ UIImage

/Users/devzkn/Library/Developer/CoreSimulator/Devices/949ED3EA-A51B-4B5C-99B1-8069EB99E684/data/Containers/Bundle/Application/2B2B99A6-4FBC-4171-BE4F-ECA1B5AA2590/09-tomcat.app/angry_00.jpg

2.3 动画结束之后清除帧动画数组

{ //开始动画 [self.imageList startAnimating]; //释放资源:动画结束之后清除帧动画数组 //nvokes a method of the receiver on the current thread using the default mode after a delay. [self performSelector:@selector(cleanUpAnimationsArray) withObject:nil afterDelay:self.imageList.animationDuration];//@interface NSObject (NSDelayedPerforming)}- (void)cleanUpAnimationsArray{ NSLog(@"%s ",__func__); //动画结束之后清除帧动画数组 [self.imageList setAnimationImages:nil];}

清除内存的代码简化

self.imageList performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.imageList.animationDuration];

III 设置状态栏字体颜色

3.1 方式一

在info.plist中,将View controller-based status bar appearance设为NO.在app delegate中:[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

3.2 方式二

VC中重写

​​-(UIStatusBarStyle)preferredStatusBarStyle​​​ 2、在viewDidload中调用:​​​[self setNeedsStatusBarAppearanceUpdate];​​

但是:当vc在nav中时,上面方法没用,vc中的preferredStatusBarStyle方法根本不用被调用。 原因是,[self setNeedsStatusBarAppearanceUpdate]发出后,只会调用navigation controller中的preferredStatusBarStyle方法,vc中的preferredStatusBarStyley方法跟本不会被调用。

解决方法:​​self.navigationController.navigationBar.barStyle = UIBarStyleBlack;​​ 或者定义一个nav bar的子类,在这个子类中重写preferredStatusBarStyle方法:

see also

CFBundleAllowMixedLocalizations 开启系统预定义的本地化功能

CFBundleAllowMixedLocalizations

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java常用工具
下一篇:背靠12亿日活用户,腾讯打造完美商业闭环,视频号或可后者居上!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~