ios UIKit框架分析 第1天
2014-05-09 10:56
411 查看
1.UIDatePicker 简单使用。
NSLocal NSTimeZone
2.UIDevice
-近距离传感器使用如打电话时屏幕的亮度变化。
@property(nonatomic,getter=isProximityMonitoringEnabled)BOOL proximityMonitoringEnabled
@property(nonatomic,readonly) BOOL proximityStateNS_AVAILABLE_IOS(3_0); //
always returns NO if no proximity detector
-检测设备类型的常见3中方法
1)使用 UI_USER_INTERFACE_IDIOM() 进行区分
(ios 3.2 >=) 无法区分iphone和ipod
if (UI_USER_INTERFACE_IDIOM()
== UIUserInterfaceIdiomPad) {
// <define your constants here>
} else {
// <define your constants here>
}
区分目前UI_USER_INTERFACE_IDIOM()有2个返回值
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone
2)使用 UIDevice.model 进行区分
(ios 2.0 >=)
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"])
{
//iPhone
}
else if([deviceType isEqualToString:@"iPod
touch"]) {
//iPod Touch
}
else {
//iPad
}
3)使用userInterfaceIdiom
3.UIFont and UIFontDescriptor(ios7)
-ios7中最新的设置font属性的方法
原文出处:/article/9745967.html
4.UIGeometry
-NSString、NSValu 与CGPoint、CGSize、CGRect等结构体之间转换的API
5.UIImage
-枚举值点击打开链接
-图片动画
UIImage还可以加载多张图片,并按指定时间间隔依次显示多张图片,这就可以非常方便地实现动画效果。UImage提供了如下方法来加载多张图片实现动画。
Ø + animatedImageNamed:duration::根据指定的图片名来加载系列图片。例如,调用该方法时的第一个参数名为butterfly,该方法将会自动加载butterfly0.png、butterfly1.png、butterfly2.png等图片。
Ø + animatedImageWithImages:duration::该方法需要传入一个NSArray作为多张动画图片。该NSArray中的每个元素都是UIImage对象。
Ø -
(UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
resizingMode:(UIImageResizingMode)resizingModeNS_AVAILABLE_IOS(6_0);该方法动态的调整图片大小。
实例:蝴蝶飞舞
NSLocal NSTimeZone
2.UIDevice
-近距离传感器使用如打电话时屏幕的亮度变化。
@property(nonatomic,getter=isProximityMonitoringEnabled)BOOL proximityMonitoringEnabled
@property(nonatomic,readonly) BOOL proximityStateNS_AVAILABLE_IOS(3_0); //
always returns NO if no proximity detector
-检测设备类型的常见3中方法
1)使用 UI_USER_INTERFACE_IDIOM() 进行区分
(ios 3.2 >=) 无法区分iphone和ipod
if (UI_USER_INTERFACE_IDIOM()
== UIUserInterfaceIdiomPad) {
// <define your constants here>
} else {
// <define your constants here>
}
区分目前UI_USER_INTERFACE_IDIOM()有2个返回值
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone
2)使用 UIDevice.model 进行区分
(ios 2.0 >=)
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"])
{
//iPhone
}
else if([deviceType isEqualToString:@"iPod
touch"]) {
//iPod Touch
}
else {
//iPad
}
3)使用userInterfaceIdiom
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) { NSLog(@"this device is iphone"); }else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){ NSLog(@"this device is ipad"); }-检测设备当前的方向
1) 使用系统定义的宏
#define UIDeviceOrientationIsPortrait(orientation) ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown)
#define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)
2) orientation
switch ([UIDevice currentDevice].orientation) { case UIDeviceOrientationPortrait: break; case UIDeviceOrientationLandscapeLeft: break; default: break; }
3.UIFont and UIFontDescriptor(ios7)
-ios7中最新的设置font属性的方法
原文出处:/article/9745967.html
4.UIGeometry
-NSString、NSValu 与CGPoint、CGSize、CGRect等结构体之间转换的API
UIKIT_EXTERN NSString *NSStringFromCGPoint(CGPoint point); UIKIT_EXTERN NSString *NSStringFromCGSize(CGSize size); UIKIT_EXTERN NSString *NSStringFromCGRect(CGRect rect); UIKIT_EXTERN NSString *NSStringFromCGAffineTransform(CGAffineTransform transform); UIKIT_EXTERN NSString *NSStringFromUIEdgeInsets(UIEdgeInsets insets); UIKIT_EXTERN CGPoint CGPointFromString(NSString *string); UIKIT_EXTERN CGSize CGSizeFromString(NSString *string); UIKIT_EXTERN CGRect CGRectFromString(NSString *string); UIKIT_EXTERN CGAffineTransform CGAffineTransformFromString(NSString *string); UIKIT_EXTERN UIEdgeInsets UIEdgeInsetsFromString(NSString *string);
5.UIImage
-枚举值点击打开链接
typedef NS_ENUM(NSInteger, UIImageResizingMode) { UIImageResizingModeTile, //平铺 UIImageResizingModeStretch,//拉伸 }; typedef NS_ENUM(NSInteger, UIImageRenderingMode) { UIImageRenderingModeAutomatic, // 根据图片的使用环境和所处的绘图上下文自动调整渲染模式。 UIImageRenderingModeAlwaysOriginal, // 始终绘制图片原始状态,不使用Tint Color。 UIImageRenderingModeAlwaysTemplate, // 始终根据Tint Color绘制图片,忽略图片的颜色信息。 } NS_ENUM_AVAILABLE_IOS(7_0);-图片拉伸
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(5_0); // create a resizable version of this image. the interior is tiled when drawn. - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0); // the interior is resized according to the resizingMode具体方法见链接/content/2605310.html
-图片动画
UIImage还可以加载多张图片,并按指定时间间隔依次显示多张图片,这就可以非常方便地实现动画效果。UImage提供了如下方法来加载多张图片实现动画。
Ø + animatedImageNamed:duration::根据指定的图片名来加载系列图片。例如,调用该方法时的第一个参数名为butterfly,该方法将会自动加载butterfly0.png、butterfly1.png、butterfly2.png等图片。
Ø + animatedImageWithImages:duration::该方法需要传入一个NSArray作为多张动画图片。该NSArray中的每个元素都是UIImage对象。
Ø -
(UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
resizingMode:(UIImageResizingMode)resizingModeNS_AVAILABLE_IOS(6_0);该方法动态的调整图片大小。
实例:蝴蝶飞舞
@implementation FKViewController UIImageView* iv; // 定义显示图片的UIImageView控件 NSTimer* timer; // 定义定时器 - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; // 设置背景色为白色 iv = [[UIImageView alloc] initWithFrame:CGRectMake(0 , 30 , 41 , 43)]; // 创建UIImageView控件 iv.image = [UIImage animatedImageNamed:@"butterfly_f" duration:0.6]; // 使用UIImageView加载文件名以butterfly_f开头的多张图片 [self.view addSubview: iv]; // 将UIImageView添加到系统界面上 // 启动NSTimer定时器来改变UIImageView的位置 timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(changePos) userInfo:nil repeats:YES]; } - (void) changePos { CGPoint curPos = iv.center; int y = arc4random() % 10 - 5; // 计算-5~5之间的一个随机数 // 当curPos的x坐标已经超过了屏幕的宽度 if(curPos.x > [UIScreen mainScreen].bounds.size.width) { iv.center = CGPointMake(0, 30); // 控制蝴蝶再次从屏幕左侧开始移动 } // 通过修改iv的center属性来改变iv控件的位置 iv.center = CGPointMake(curPos.x + 4, curPos.y + y); } @end
相关文章推荐
- ios UIKit框架分析 第4天
- ios UIKit框架分析 第5天
- ios UIKit框架分析 第6天
- ios UIKit框架分析 第8天
- ios UIKit框架分析 第9天
- ios UIKit框架分析 第2天
- ios UIKit框架分析 第7天
- ios UIKit框架分析 第3天
- IOS UIKit框架之窗口和视图架构介绍
- UIKit 框架图- iOS开发需要不断的深入理解
- iOS基础-UIKit框架-触摸事件-事件传递
- IOS开发笔记--UIKit框架之 UIView
- iOS开发资源分享:UIKit关键帧动画框架Jazz Hands、MTLog、Pocket Weather源码以及其他
- iOS基础-UIKit框架-多控制器管理-UINavigationController、控制器的生命周期
- iOS开发UIKit框架-可视化编程-XIB
- iOS基础-UIKit框架-多控制器管理-UITabBarController
- iOS 10越狱和Reveal 8分析三方App UI框架教程
- iOS开发UIKit框架-可视化编程-XIB
- iOS 10越狱和Reveal 8分析三方App UI框架教程
- iOS学习笔记-128.SDWebImage4——框架内部调用简单分析