在UIKit中谁才最我们的敌人?

我们在开发iOS的过程中,都在调用系统的类,每个类都有丰富的API,但是在开的中很多类型与API我们是用不着的.

当系统的类满不了我们的需要的时候,我就就需要Custom了.在Custom不要贪途方便什么都放一堆.

看看以下这个表,你发现这些对象在内存的大小.相信还有不少人还是不知道的.单位为Bytes

/*

2016-03-04 20:15:55.218 Debug[25079:992455] UIAcceleration---- 40
2016-03-04 20:15:55.219 Debug[25079:992455] UIAccelerometer---- 40
2016-03-04 20:15:55.219 Debug[25079:992455] UIBarItem---- 16
2016-03-04 20:15:55.219 Debug[25079:992455] UIBarButtonItem---- 272
2016-03-04 20:15:55.219 Debug[25079:992455] UITabBarItem---- 168
2016-03-04 20:15:55.220 Debug[25079:992455] UIBezierPath---- 96
2016-03-04 20:15:55.220 Debug[25079:992455] UIColor---- 16
2016-03-04 20:15:55.220 Debug[25079:992455] UIDevice---- 24
2016-03-04 20:15:55.220 Debug[25079:992455] UIEvent---- 32
2016-03-04 20:15:55.221 Debug[25079:992455] UIGestureRecognizer---- 232
2016-03-04 20:15:55.221 Debug[25079:992455] UILongPressGestureRecognizer---- 384
2016-03-04 20:15:55.221 Debug[25079:992455] UIPanGestureRecognizer---- 384
2016-03-04 20:15:55.221 Debug[25079:992455] UIPinchGestureRecognizer---- 384
2016-03-04 20:15:55.221 Debug[25079:992455] UIRotationGestureRecognizer---- 336
2016-03-04 20:15:55.222 Debug[25079:992455] UISwipeGestureRecognizer---- 352
2016-03-04 20:15:55.222 Debug[25079:992455] UITapGestureRecognizer---- 272
2016-03-04 20:15:55.222 Debug[25079:992455] UIImage---- 80
2016-03-04 20:15:55.222 Debug[25079:992455] UILocalizedIndexedCollation---- 80
2016-03-04 20:15:55.262 Debug[25079:992455] UILocalNotification---- 8
2016-03-04 20:15:55.262 Debug[25079:992455] UIMenuController---- 48
2016-03-04 20:15:55.262 Debug[25079:992455] UIMenuItem---- 32
2016-03-04 20:15:55.262 Debug[25079:992455] UINavigationItem---- 240
2016-03-04 20:15:55.262 Debug[25079:992455] UINib---- 16
2016-03-04 20:15:55.263 Debug[25079:992455] UIPasteboard---- 16
2016-03-04 20:15:55.263 Debug[25079:992455] UIPopoverController---- 480
2016-03-04 20:15:55.263 Debug[25079:992455] UIPrintFormatter---- 120
2016-03-04 20:15:55.263 Debug[25079:992455] UISimpleTextPrintFormatter---- 120
2016-03-04 20:15:55.263 Debug[25079:992455] UIMarkupTextPrintFormatter---- 144
2016-03-04 20:15:55.264 Debug[25079:992455] UIViewPrintFormatter---- 128
2016-03-04 20:15:55.264 Debug[25079:992455] UIPrintInfo---- 80
2016-03-04 20:15:55.264 Debug[25079:992455] UIPrintInteractionController---- 128
2016-03-04 20:15:55.264 Debug[25079:992455] UIPrintPageRenderer---- 112
2016-03-04 20:15:55.265 Debug[25079:992455] UIPrintPaper---- 24
2016-03-04 20:15:55.265 Debug[25079:992455] UIResponder---- 16
2016-03-04 20:15:55.265 Debug[25079:992455] UIApplication---- 656
2016-03-04 20:15:55.265 Debug[25079:992455] UIView---- 368
2016-03-04 20:15:55.265 Debug[25079:992455] UIViewController---- 784
2016-03-04 20:15:55.266 Debug[25079:992455] UITabBarController---- 992
2016-03-04 20:15:55.266 Debug[25079:992455] UITableViewController---- 832
2016-03-04 20:15:55.266 Debug[25079:992455] UINavigationController---- 1080
2016-03-04 20:15:55.266 Debug[25079:992455] UIImagePickerController---- 1160
2016-03-04 20:15:55.267 Debug[25079:992455] UIVideoEditorController---- 1104
2016-03-04 20:15:55.267 Debug[25079:992455] UIWindow---- 776
2016-03-04 20:15:55.267 Debug[25079:992455] UILabel---- 520
2016-03-04 20:15:55.267 Debug[25079:992455] UIPickerView---- 520
2016-03-04 20:15:55.268 Debug[25079:992455] UIActivityIndicatorView---- 520
2016-03-04 20:15:55.268 Debug[25079:992455] UIImageView---- 432
2016-03-04 20:15:55.268 Debug[25079:992455] UITabBar---- 592
2016-03-04 20:15:55.269 Debug[25079:992455] UIToolbar---- 464
2016-03-04 20:15:55.269 Debug[25079:992455] UINavigationBar---- 568
2016-03-04 20:15:55.269 Debug[25079:992455] UITableViewCell---- 976
2016-03-04 20:15:55.270 Debug[25079:992455] UIActionSheet---- 456
2016-03-04 20:15:55.270 Debug[25079:992455] UIAlertView---- 488
2016-03-04 20:15:55.270 Debug[25079:992455] UIScrollView---- 1104
2016-03-04 20:15:55.270 Debug[25079:992455] UISearchBar---- 656
2016-03-04 20:15:55.289 Debug[25079:992455] UIWebView---- 376
2016-03-04 20:15:55.289 Debug[25079:992455] UIControl---- 408
2016-03-04 20:15:55.290 Debug[25079:992455] UITableView---- 2112
2016-03-04 20:15:55.290 Debug[25079:992455] UITextView---- 1344
2016-03-04 20:15:55.290 Debug[25079:992455] UIButton---- 664
2016-03-04 20:15:55.290 Debug[25079:992455] UIDatePicker---- 424
2016-03-04 20:15:55.290 Debug[25079:992455] UIPageControl---- 520
2016-03-04 20:15:55.291 Debug[25079:992455] UISegmentedControl---- 488
2016-03-04 20:15:55.291 Debug[25079:992455] UITextField---- 824
2016-03-04 20:15:55.291 Debug[25079:992455] UISlider---- 560
2016-03-04 20:15:55.292 Debug[25079:992455] UISwitch---- 448
2016-03-04 20:15:55.322 Debug[25079:992455] UIScreen---- 352
2016-03-04 20:15:55.323 Debug[25079:992455] UIScreenMode---- 24
2016-03-04 20:15:55.323 Debug[25079:992455] UISearchDisplayController---- 312
2016-03-04 20:15:55.323 Debug[25079:992455] UITextChecker---- 24
2016-03-04 20:15:55.323 Debug[25079:992455] UITextInputStringTokenizer---- 16
2016-03-04 20:15:55.323 Debug[25079:992455] UITextPosition---- 8
2016-03-04 20:15:55.324 Debug[25079:992455] UITextRange---- 8
2016-03-04 20:15:55.324 Debug[25079:992455] UITouch---- 296

*/

NSLog(@"UIAcceleration---- %lu",class_getInstanceSize([UIAcceleration class]));
    NSLog(@"UIAccelerometer---- %lu",class_getInstanceSize([UIAccelerometer class]));
    
    NSLog(@"UIBarItem---- %lu",class_getInstanceSize([UIBarItem class]));
    NSLog(@"UIBarButtonItem---- %lu",class_getInstanceSize([UIBarButtonItem class]));
    NSLog(@"UITabBarItem---- %lu",class_getInstanceSize([UITabBarItem class]));
    
    NSLog(@"UIBezierPath---- %lu",class_getInstanceSize([UIBezierPath class]));
    NSLog(@"UIColor---- %lu",class_getInstanceSize([UIColor class]));
    NSLog(@"UIDevice---- %lu",class_getInstanceSize([UIDevice class]));
    NSLog(@"UIEvent---- %lu",class_getInstanceSize([UIEvent class]));
    
    NSLog(@"UIGestureRecognizer---- %lu",class_getInstanceSize([UIGestureRecognizer class]));
    NSLog(@"UILongPressGestureRecognizer---- %lu",class_getInstanceSize([UILongPressGestureRecognizer class]));
    NSLog(@"UIPanGestureRecognizer---- %lu",class_getInstanceSize([UIPanGestureRecognizer class]));
    NSLog(@"UIPinchGestureRecognizer---- %lu",class_getInstanceSize([UIPinchGestureRecognizer class]));
    NSLog(@"UIRotationGestureRecognizer---- %lu",class_getInstanceSize([UIRotationGestureRecognizer class]));
    NSLog(@"UISwipeGestureRecognizer---- %lu",class_getInstanceSize([UISwipeGestureRecognizer class]));
    NSLog(@"UITapGestureRecognizer---- %lu",class_getInstanceSize([UITapGestureRecognizer class]));
    
    NSLog(@"UIImage---- %lu",class_getInstanceSize([UIImage class]));
    
    NSLog(@"UILocalizedIndexedCollation---- %lu",class_getInstanceSize([UILocalizedIndexedCollation class]));
    NSLog(@"UILocalNotification---- %lu",class_getInstanceSize([UILocalNotification class]));
    NSLog(@"UIMenuController---- %lu",class_getInstanceSize([UIMenuController class]));
    NSLog(@"UIMenuItem---- %lu",class_getInstanceSize([UIMenuItem class]));
    NSLog(@"UINavigationItem---- %lu",class_getInstanceSize([UINavigationItem class]));
    NSLog(@"UINib---- %lu",class_getInstanceSize([UINib class]));
    NSLog(@"UIPasteboard---- %lu",class_getInstanceSize([UIPasteboard class]));
    NSLog(@"UIPopoverController---- %lu",class_getInstanceSize([UIPopoverController class]));
    NSLog(@"UIPrintFormatter---- %lu",class_getInstanceSize([UIPrintFormatter class]));
    NSLog(@"UISimpleTextPrintFormatter---- %lu",class_getInstanceSize([UISimpleTextPrintFormatter class]));
    NSLog(@"UIMarkupTextPrintFormatter---- %lu",class_getInstanceSize([UIMarkupTextPrintFormatter class]));
    NSLog(@"UIViewPrintFormatter---- %lu",class_getInstanceSize([UIViewPrintFormatter class]));
    NSLog(@"UIPrintInfo---- %lu",class_getInstanceSize([UIPrintInfo class]));
    NSLog(@"UIPrintInteractionController---- %lu",class_getInstanceSize([UIPrintInteractionController class]));
    NSLog(@"UIPrintPageRenderer---- %lu",class_getInstanceSize([UIPrintPageRenderer class]));
    NSLog(@"UIPrintPaper---- %lu",class_getInstanceSize([UIPrintPaper class]));
    
    NSLog(@"UIResponder---- %lu",class_getInstanceSize([UIResponder class]));
    NSLog(@"UIApplication---- %lu",class_getInstanceSize([UIApplication class]));
    NSLog(@"UIView---- %lu",class_getInstanceSize([UIView class]));
    NSLog(@"UIViewController---- %lu",class_getInstanceSize([UIViewController class]));
    NSLog(@"UITabBarController---- %lu",class_getInstanceSize([UITabBarController class]));
    NSLog(@"UITableViewController---- %lu",class_getInstanceSize([UITableViewController class]));
    NSLog(@"UINavigationController---- %lu",class_getInstanceSize([UINavigationController class]));
    NSLog(@"UIImagePickerController---- %lu",class_getInstanceSize([UIImagePickerController class]));
    NSLog(@"UIVideoEditorController---- %lu",class_getInstanceSize([UIVideoEditorController class]));
    
    
    NSLog(@"UIWindow---- %lu",class_getInstanceSize([UIWindow class]));
    NSLog(@"UILabel---- %lu",class_getInstanceSize([UILabel class]));
    NSLog(@"UIPickerView---- %lu",class_getInstanceSize([UIPickerView class]));
    NSLog(@"UIActivityIndicatorView---- %lu",class_getInstanceSize([UIActivityIndicatorView class]));
    NSLog(@"UIImageView---- %lu",class_getInstanceSize([UIImageView class]));
    NSLog(@"UITabBar---- %lu",class_getInstanceSize([UITabBar class]));
    NSLog(@"UIToolbar---- %lu",class_getInstanceSize([UIToolbar class]));
    NSLog(@"UINavigationBar---- %lu",class_getInstanceSize([UINavigationBar class]));
    NSLog(@"UITableViewCell---- %lu",class_getInstanceSize([UITableViewCell class]));
    NSLog(@"UIActionSheet---- %lu",class_getInstanceSize([UIActionSheet class]));
    NSLog(@"UIAlertView---- %lu",class_getInstanceSize([UIAlertView class]));
    NSLog(@"UIScrollView---- %lu",class_getInstanceSize([UIScrollView class]));
    NSLog(@"UISearchBar---- %lu",class_getInstanceSize([UISearchBar class]));
    NSLog(@"UIWebView---- %lu",class_getInstanceSize([UIWebView class]));
    NSLog(@"UIControl---- %lu",class_getInstanceSize([UIControl class]));

NSLog(@"UITableView---- %lu",class_getInstanceSize([UITableView class]));
    NSLog(@"UITextView---- %lu",class_getInstanceSize([UITextView class]));
    
    NSLog(@"UIButton---- %lu",class_getInstanceSize([UIButton class]));
    NSLog(@"UIDatePicker---- %lu",class_getInstanceSize([UIDatePicker class]));
    NSLog(@"UIPageControl---- %lu",class_getInstanceSize([UIPageControl class]));
    NSLog(@"UISegmentedControl---- %lu",class_getInstanceSize([UISegmentedControl class]));
    NSLog(@"UITextField---- %lu",class_getInstanceSize([UITextField class]));
    NSLog(@"UISlider---- %lu",class_getInstanceSize([UISlider class]));
    NSLog(@"UISwitch---- %lu",class_getInstanceSize([UISwitch class]));
    
    
    NSLog(@"UIScreen---- %lu",class_getInstanceSize([UIScreen class]));
    NSLog(@"UIScreenMode---- %lu",class_getInstanceSize([UIScreenMode class]));
    NSLog(@"UISearchDisplayController---- %lu",class_getInstanceSize([UISearchDisplayController class]));
    NSLog(@"UITextChecker---- %lu",class_getInstanceSize([UITextChecker class]));
    NSLog(@"UITextInputStringTokenizer---- %lu",class_getInstanceSize([UITextInputStringTokenizer class]));
    NSLog(@"UITextPosition---- %lu",class_getInstanceSize([UITextPosition class]));
    NSLog(@"UITextRange---- %lu",class_getInstanceSize([UITextRange class]));
    NSLog(@"UITouch---- %lu",class_getInstanceSize([UITouch class]));

由此可得出,往往我们的APP开发到一个某时期的时候就会发现页面开卡顿,UITableView\UITableViewCell最占内存,开始自定义吧!

时间: 2024-10-11 03:54:38

在UIKit中谁才最我们的敌人?的相关文章

Swift:UIKit中Demo(一)

关于Swift的基本概念及语法知识.我在前面的章节中已经介绍了非常多.这一节和下一节主要有针对性的解说Swift在实际UIKit开发中的使用场景及注意点.先来看看Demo的终于效果图. Demo分析: 1. 界面上面有三个button,他们的宽度不一致. 2. 点击每一个button的时候.以下有红色下划线跟着"走动". 一. Storyboard中的设计 注意到,这个红色下划线是任意摆放的.没有刻意的设置它的位置及宽度.而这个红色下划线也就是一个简单的UIView. 二. 拖线工作

swift:UIKit中Demo(二)

这一节,继续为大家提供一个Demo,用来说明Swift中的各种语法及在UIView中的基本使用.效果图如下: 看起来,这个Demo非常的简单.但是为了进行详细的语法说明,它的实现,均是用代码实现的,并且下方的进度条都是"组装"起来的. 结构分析: 1. 有一个根控制器ViewController.swift, 它只是用来展示上面显示的文字(秋恨雪). 2. 然后下面的文字大小切换及进度条这个整体是一个自定义的View(LFFontView.swift) 3. 进度条部分又有三部分内容组

通过标准的Runtime API(C函数)打印UIKit中UIView的所有变量、属性以及方法

Ivar:定义对象的实例变量,包括类型和名字.objc_property_t:定义属性.叫这个名字可能是为了防止和Objective-C 1.0中的用户类型冲突,那时候还没有属性.Method:定义对象方法或类方法.这个类型提供了方法的名字(就是**选择器**).参数数量和类型,以及返回值(这些信息合起来称为方法的**签名**),还有一个指向代码的函数指针(也就是方法的**实现**).SEL:定义选择器.选择器是方法名的唯一标识符,我理解它就是个字符串. 下面是一些运行代码和对应日止 + (vo

【找出平面中的距离自己最近的敌人】 不用计算距离

  #include <iostream> using namespace std; //自己坐标 敌人的坐标(a,b) double a[6]={0,1,2,3,4,5}; double b[6]={0,1,2,3,4,5}; double c[6]={999}; int who=0; void fun() {     for(int i=1;i<6;i++)      {          a[i]-=a[0];b[i]-=b[0];      }      for(int i=1;

[爱上Swift] day8:讲解Swift中的UIKit重力学(一)

转自:http://www.itjhwd.com/swift-uikitzlx/ 重力学这个名词不论在哪个行业领域听起来似乎都很高大上.那么在Swift中的重力学是什么呢?那就是将我们移动端屏幕上毫无生命力的东西也置于万有引力中,使它们能够展现出好像真的由于引力而向下坠落以及碰到物体后自然的弹开的效果. 要想做到这一点,我们得需要两个利器:UIKit Dynamics和Motion Effects. UIKit Dynamics是UIKit中一套完整的物理引擎.它可以让我们在程序中对界面元素添加

iOS开发笔记--iOS中的多线程

摘要 本文主要介绍iOS开发中的三种多线程技术:NSThread, NSOperation/NSOperationQueue, GCD.以及在多线程编程中的注意点和小技巧. 多线程 NSThread NSOperation/NSOperationQueue GCD 目录[-] iOS中的多线程 iOS的三种多线程技术特点: GCD基本思想 队列: 操作: 不同队列中嵌套同步操作dispatch_sync的结果: 同步操作dispatch_sync的应用场景: GCD优点: GCD队列: NSOp

如何自定义iOS中的控件

本文译自 How to build a custom control in iOS .大家要是有什么问题,可以直接在 twitter 上联系原作者,当然也可以在最后的评论中回复我. 在开发过程中,有时候UIKit的标准控件并不能满足我们的需求,例如你需要一个控件能支持用户方便的选择0-360°之间的一个角度值,此时就需要根据自己的需求自定义控件了. 对于选择角度值的控件可以这样实现:创建一个圆形的滑块,用户通过拖动手柄操作就能选择角度值.实际上这样的控件在别的一些平台中你可能看到过,但是在UIK

说说iOS中的手势及触摸

一.响应链 在IOS开发中会遇到各种操作事件,通过程序可以对这些事件做出响应. 首先,当发生事件响应时,必须知道由谁来响应事件.在IOS中,由响应者链来对事件进行响应,所有事件响应的类都是UIResponder的子类,响应者链是一个由不同对象组成的层次结构,其中的每个对象将依次获得响应事件消息的机会.当发生事件时,事件首先被发送给第一响应者,第一响应者往往是事件发生的视图,也就是用户触摸屏幕的地方.事件将沿着响应者链一直向下传递,直到被接受并做出处理.一般来说,第一响应者是个视图对象或者其子类对

iOS7中Objective-C和Foundation的新特性

转自kingzwt2009的专栏 注意事项(Ray):文章来自iOS 7 by Tutorials  iOS 7Feast的一部分(略) Objective-C 是最重要的iOS和OSX apps的开发工具.你可以使用其他语言的第三方框架开发apps,例如HTML&Javascript或者C#,但是如果你很快的写出一个超炫的高效率的原声apps你就需要使Objective-C. Foundation 是你开发Objective-C应用时用到的核心框架之一. 作为一名iOS开发者,非常有必要了解最