UIBarMetrics

1
2
3
4
5
6
7
forBarMetrics有点类似于按钮的for state状态,即什么状态下显示

//UIBarMetricsDefault-竖屏横屏都有,横屏导航条变宽,则自动repeat图片

//UIBarMetricsCompact-竖屏没有,横屏有,相当于之前老iOS版本里地UIBarMetricsLandscapePhone

//UIBarMetricsCompactPrompt和UIBarMetricsDefaultPrompt暂时不知道用处,官方解释是Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar,

UIBlurEffect系统自带毛玻璃效果

`objc
//需要模糊效果的view
UIImageView*i = [[UIImageViewalloc]initWithFrame:CGRectMake(100,100,100,200)];
[self.viewaddSubview:i];
i.image= [UIImageimageNamed:@”1”];

//创建UIBlurEffect
UIBlurEffect*blurEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight];

//UIVisualEffectView
UIVisualEffectView*effectView = [[UIVisualEffectViewalloc]initWithEffect:blurEffect]; //设置模糊效果的frame effectView.frame = i.bounds; //添加到view上 [iaddSubview:effectView]; //设置模糊的程度 effectView.alpha =.5f;
typedefNS_ENUM(NSInteger, UIBlurEffectStyle) { UIBlurEffectStyleExtraLight, UIBlurEffectStyleLight,
UIBlurEffectStyleDark}

UIColor和TintColor

前者是指颜色,tint是指着色,色调。
通过tintColor属性可以定制UINavigationBar的背景颜色,但如果需要设定渐变色、甚至纹理来说,就需要贴图了。比较“暴力”的一种做法就是通过Category来重新实现- (void)
drawRect:(CGRect)rect的实现,“暴力”是因为这种杀伤面很广,所有项目内的UINavigationBar都会因此改变。

UIControlEvents

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
UIControlEventstypedefNS_OPTIONS(NSUInteger,
UIControlEvents) {    UIControlEventTouchDown           =1<< 0,     // on all touch downs
    UIControlEventTouchDownRepeat     =1<< 1,     // on multiple touchdowns (tap count > 1)
    UIControlEventTouchDragInside     =1<< 2,
    UIControlEventTouchDragOutside    =1<< 3,
    UIControlEventTouchDragEnter      =1<< 4,
    UIControlEventTouchDragExit       =1<< 5,
    UIControlEventTouchUpInside       =1<< 6,
    UIControlEventTouchUpOutside      =1<< 7,
    UIControlEventTouchCancel         =1<< 8,

    UIControlEventValueChanged        =1<<12,    // sliders, etc.

    UIControlEventEditingDidBegin     =1<<16,    // UITextField
    UIControlEventEditingChanged      =1<<17,
    UIControlEventEditingDidEnd       =1<<18,
    UIControlEventEditingDidEndOnExit =1<<19,    // 'return key' ending editing

    UIControlEventAllTouchEvents      =0x00000FFF// for touch events
    UIControlEventAllEditingEvents    =0x000F0000// for UITextField
    UIControlEventApplicationReserved =0x0F000000// range available for application use
    UIControlEventSystemReserved      =0xF0000000// range reserved for internal framework use
    UIControlEventAllEvents           =0xFFFFFFFF};/*
 UIControlEventTouchDown 单点触摸按下事件:用户点触屏幕,或者又有新手指落下的时候。
 UIControlEventTouchDownRepeat 多点触摸按下事件,点触计数大于1:用户按下第二、三、或第四根手指的时候。
 UIControlEventTouchDragInside 当一次触摸在控件窗口内拖动时。
 UIControlEventTouchDragOutside 当一次触摸在控件窗口之外拖动时。
 UIControlEventTouchDragEnter 当一次触摸从控件窗口之外拖动到内部时。
 UIControlEventTouchDragExit
 当一次触摸从控件窗口内部拖动到外部时。
 
 UIControlEventTouchUpInside 所有在控件之内触摸抬起事件。
 UIControlEventTouchUpOutside 所有在控件之外触摸抬起事件(点触必须开始与控件内部才会发送通知)。
 UIControlEventTouchCancel 所有触摸取消事件,即一次触摸因为放上了太多手指而被取消,或者被上锁或者电话呼叫打断。
 UIControlEventTouchChanged 当控件的值发生改变时,发送通知。用于滑块、分段控件、以及其他取值的控件。你可以配置滑块控件何时发送通知,在滑块被放下时发送,或者在被拖动时发送。
 UIControlEventEditingDidBegin 当文本控件中开始编辑时发送通知。
 UIControlEventEditingChanged 当文本控件中的文本被改变时发送通知。
 UIControlEventEditingDidEnd 当文本控件中编辑结束时发送通知。
 UIControlEventEditingDidOnExit 当文本控件内通过按下回车键(或等价行为)结束编辑时,发送通知。
 UIControlEventAlltouchEvents 通知所有触摸事件。
 UIControlEventAllEditingEvents 通知所有关于文本编辑的事件。
 UIControlEventAllEvents
 通知所有事件。
       */

UIDevice

UIDevice提供了多种属性、类函数及状态通知,帮助我们全方位了解设备状况。从检测电池电量到定位设备与临近感应,UIDevice所做的工作就是为应用程序提供用户及设备的一些信息。UIDevice类还能够收集关于设备的各种具体细节,例如机型及iOS版本等。其中大部分属性都对开发工作具有积极的辅助作用。下面的代码简单的使用UIDevice获取手机属性。

UIGestureRecognizerState

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
typedef NS_ENUM(NSInteger, UIGestureRecognizerState) {
UIGestureRecognizerStatePossible, // the recognizer has not yet recognized its gesture, but may be evaluating touch events. this is the default state

UIGestureRecognizerStateBegan, // the recognizer has received touches recognized as the gesture. the action method will be called at the next turn of the run loop
UIGestureRecognizerStateChanged, // the recognizer has received touches recognized as a change to the gesture. the action method will be called at the next turn of the run loop
UIGestureRecognizerStateEnded, // the recognizer has received touches recognized as the end of the gesture. the action method will be called at the next turn of the run loop and the recognizer will be reset to UIGestureRecognizerStatePossible
UIGestureRecognizerStateCancelled, // the recognizer has received touches resulting in the cancellation of the gesture. the action method will be called at the next turn of the run loop. the recognizer will be reset to UIGestureRecognizerStatePossible

UIGestureRecognizerStateFailed, // the recognizer has received a touch sequence that can not be recognized as the gesture. the action method will not be called and the recognizer will be reset to UIGestureRecognizerStatePossible

// Discrete Gestures – gesture recognizers that recognize a discrete event but do not report changes (for example, a tap) do not transition through the Began and Changed states and can not fail or be cancelled
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded // the recognizer has received touches recognized as the gesture. the action method will be called at the next turn of the run loop and the recognizer will be reset to UIGestureRecognizerStatePossible
};

Possible: 识别器在未识别出它的手势,但可能会接收到触摸时处于这个状态。这是默认状态。
Began: 识别器接收到触摸并识别出是它的手势时处于这个状态。响应方法将在下个循环步骤中被调用。

Changed:the recognizer has received touches recognized as a change to the gesture. (不懂怎么翻译,理解上就是识别器识别出一个变化为它的手势的触摸),响应方法将在下个循环步骤中被调用。

Ended:识别器在识别到作为当前手势结束信号的触摸时处于这个状态。响应方法将在下个循环步骤中被调用 并且 识别器将重置为possible状态。

Cancelled:识别器处于取消状态.响应方法将在下个循环步骤中被调用 并且 识别器将重置为possible状态。

Failed: 识别器接收到不能识别为它的手势的一系列触摸。响应方法不会被调用 并且 识别器将重置为possible状态。

Recognized: 识别器已识别到它的手势。响应方法将在下个循环步骤中被调用 并且 识别器将重置为possible状态。

UIDatePicker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 200, 375, 267)];

self.datePicker.backgroundColor = [UIColor whiteColor];

//设置地区
self.datePicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];



//设置DatePicker的日历,默认为当天。
self.datePicker.calendar = [NSCalendar currentCalendar];

//设置时区
self.datePicker.timeZone = [NSTimeZone defaultTimeZone];

//选择时区
// [self.datePicker setTimeZone:[NSTimeZone timeZoneWithName:@"GMT+8"]];


// 设置当前显示时间

NSDate *currentTime = [NSDate date];

self.datePicker.date = currentTime;

// 设置显示最大时间

self.datePicker.maximumDate = currentTime;

// 显示模式
[self.datePicker setDatePickerMode:UIDatePickerModeDate];

//倒计时按秒显示
self.datePicker.countDownDuration = 600;

//设置分钟间隔
self.datePicker.minuteInterval = 10;

// 回调的方法
[self.datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];


[self.view addSubview:self.datePicker];

}

-(void)datePickerValueChanged:(id)sender
{
NSDate *selected = [NSDate date];
NSLog(@"date: %@", selected);
}

UINavigationController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
属性 :
viewControllers属性: 存储了栈中的所有被管理的控制器
navigationController属性: 父类中的属性,每个在栈中的控制器,都能 通过此属性,获取自己所在的UINavigationController对象。
/***********创建导航控制器***********************/
RootViewController *rootVC = [[RootViewControlleralloc]init];

//创建一个导航控制器
UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:rootVC];
[rootVC release];

//指定导航控制器为window的根视图
self.window.rootViewController = naVC;
[naVC release];
/*****************************************************/


/****************设置导航栏外观***********************/
//导航栏背景颜色
naVC.navigationBar.barTintColor = [UIColor purpleColor];
//设置导航栏不显示半透明效果
naVC.navigationBar.translucent = NO;
//将导航栏隐藏
naVC.navigationBar.hidden = NO;
//设置背景图片
UIImage *image = [UIImage imageNamed:@"bk.png"];
[naVC.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];


/****************设置导航栏内容***********************/
//设置导航栏上的内容:navigationItem
//title
self.navigationItem.title = @"第二页";

//titleView
UISegmentedControl *segmentC = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"消息",@"通话", nil]];

[segmentC addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventEditingChanged];

self.navigationItem.titleView = segmentC;
[segmentC release];


//设置自定义内容放在左侧
UITextField *textf = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
textf.backgroundColor = [UIColor yellowColor];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:textf];




//自定义导航栏左侧按钮
UIImage *image = [UIImage imageNamed:@"1.png"];
//取消渲染
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(leftBarAction:)]autorelease];

-(void)leftBarAction:(UIBarButtonItem *)barItem
{
[self.navigationController popViewControllerAnimated:YES];
}

//自定义导航栏右侧按钮为可以编辑Edit
self.navigationItem.rightBarButtonItem = self.editButtonItem;

/****************编辑***********************/
//重写系统编辑按钮触发的方法
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];

//通过系统编辑按钮控制tableview的编辑状态
[self.tableView setEditing:editing animated:animated];
}

//隐藏导航栏返回按钮
self.navigationItem.hidesBackButton =YES;

//自定义导航栏右侧按钮
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithTitle:@"下一页" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarAction:)]autorelease];


}
-(void)rightBarAction:(UIBarButtonItem *)barItem
{
SecondViewController *sVC = [[SecondViewController alloc]init];
[self.navigationController pushViewController:sVC animated:YES];
[sVC release];
}
/*****************************************************/


/****************跳转页面的方法***********************/
pushViewController:animated //进入下一个视图控制器
popViewControllerAnimated: //返回上一个视图控制器
popToViewController:animated //返回到指定的视图控制器
popToRootViewControllerAnimated //返回到根视图控制器
//进入下一页
SecondViewController *secondVC = [[SecondViewController alloc]init];

[self.navigationController pushViewController:secondVC animated:YES];

//返回上一页
[self.navigationController popViewControllerAnimated:YES];

//跳到根页面
[self.navigationController popToRootViewControllerAnimated:YES];


//跳到指定页面
UIViewController *vc =
[self.navigationController.viewControllers objectAtIndex:0];

[self.navigationController popToViewController:vc animated:YES];
/*****************************************************/

自定义导航栏左侧按钮后恢复右拉返回功能
self.navigationController.interactivePopGestureRecognizer.delegate=(id)self;

UIImagePickerController从本地相册加载图片

/*1.签两个协议协议
UIImagePickerControllerDelegate
UINavigationControllerDelegate
2.两个方法

方法一:
//点击按钮触发的方法
-(void)buttonAction:(UIButton*)button
{

//创建获取本地相册控制器对象
UIImagePickerController *picker = [[UIImagePickerControlleralloc]init];

//成为代理
picker.delegate= self;

//设置相片来源类型
picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

//是否可以编辑
picker.allowsEditing= YES;

//模态显示本地相册
[selfpresentViewController:pickeranimated:YEScompletion:^{


}]; 

}

方法二:
//当用户选择相册中的某个图片时触发的方法,协议里的方法
//该方法可以获取到选中的图片

  • (void)imagePickerController:(UIImagePickerController)picker didFinishPickingMediaWithInfo:(NSDictionary)info
    {

    NSLog(@”info = %@”,info);
    UIImage image=
    [info objectForKey:@”UIImagePickerControllerOriginalImage”];
    //通过tag值取对象
    UIButton
    button = (UIButton*)[self.viewviewWithTag:10000];
    [button setBackgroundImage:imageforState:UIControlStateNormal];

    //让相册模态消失
    [picker dismissViewControllerAnimated:YEScompletion:^{

}];

}
数据来源类型一共有三种:
enum {
UIImagePickerControllerSourceTypePhotoLibrary ,//来自图库
UIImagePickerControllerSourceTypeCamera ,//来自相机
UIImagePickerControllerSourceTypeSavedPhotosAlbum //来自相册
};
在用这些来源的时候最好检测以下设备是否支持;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
NSLog(@”支持相机”);
}
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
NSLog(@”支持图库”);
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
NSLog(@”支持相片库”);
}

调用摄像头来获取资源

  • (void)viewDidLoad {
    [super viewDidLoad];
    picker = [[UIImagePickerController alloc]init];
    picker.view.backgroundColor = [UIColor orangeColor];
    UIImagePickerControllerSourceType sourcheType = UIImagePickerControllerSourceTypeCamera;
    picker.sourceType = sourcheType;
    picker.delegate = self;
    picker.allowsEditing = YES;
    }

`

UIPageControl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  /*****************创建UIPageControl*********************/
//创建UIPageControl
self.pageC= [[UIPageControlalloc]initWithFrame:CGRectMake((WIDTH-300)/2,HEIGHT-60,300,50)];
[self.viewaddSubview:self.pageC];
[self.pageCrelease];

//设置页数
self.pageC.numberOfPages =10;

//设置当前页码的颜色
self.pageC.currentPageIndicatorTintColor = [UIColoryellowColor];

//设置所有页的颜色
self.pageC.pageIndicatorTintColor= [UIColorredColor];

//核心方法
[self.pageCaddTarget:selfaction:@selector(pageAction:)forControlEvents:UIControlEventValueChanged];


self.scroll.delegate= self;

}
-(void)pageAction:(UIPageControl*)pageC
{
//打印当前页码

NSLog(@"切换页码= %ld ",(long)pageC.currentPage);

//页面跟着page的点动
[self.scrollsetContentOffset:CGPointMake(375*self.pageC.currentPage,0)animated:YES];


}
/*****************************************************/
|