@property(nonatomic,readonly) NSArray *childViewControllers
- (void)addChildViewController:(UIViewController *)childController
- (void) removeFromParentViewCont
- (void)willMoveToParentViewCont
- (void)didMoveToParentViewContr
- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(5_0);
交换两个子视图控制器的位置(由于添加的顺序不同,所以子试图控制器在父视图控制器中存在层次关系)fromViewController:当前显示的子试图控制器,将被替换为非显示状态
toViewController:将要显示的子视图控制器
duration:交换动画持续的时间,单位秒
options:动画的方式
animations:动画Block
completion:完成后执行的Block
详细描述请参考:http://blog.sina.com.cn/s/blog_7b9d64af0101d6p7.html
2.UIPageViewController 属性方法简单介绍
typedef NS_ENUM(NSInteger, UIPageViewControllerNavigationOrientation) {
UIPageViewControllerNavigationOrientationHorizontal = 0, 水平方向翻页
UIPageViewControllerNavigationOrientationVertical = 1 垂直方向翻页
};
typedef NS_ENUM(NSInteger, UIPageViewControllerSpineLocation) { 书脊在屏幕中的位置
UIPageViewControllerSpineLocationNone = 0, // Returned if 'spineLocation' is queried when 'transitionStyle' is not 'UIPageViewControllerTransitionStylePageCurl'. scroll类型时没有书脊
UIPageViewControllerSpineLocationMin = 1, // Requires one view controller.书脊在屏幕左端
UIPageViewControllerSpineLocationMid = 2, // Requires two view controllers.书脊在屏幕中间,需要2个内容控制器
UIPageViewControllerSpineLocationMax = 3 // Requires one view controller.书脊在屏幕右端
}; // Only pertains to 'UIPageViewControllerTransitionStylePageCurl'.
typedef NS_ENUM(NSInteger, UIPageViewControllerNavigationDirection) {翻页的方向 左-右 低端-顶端
UIPageViewControllerNavigationDirectionForward,
UIPageViewControllerNavigationDirectionReverse
}; // For 'UIPageViewControllerNavigationOrientationHorizontal', 'forward' is right-to-left, like pages in a book. For 'UIPageViewControllerNavigationOrientationVertical', bottom-to-top, like pages in a wall calendar.
typedef NS_ENUM(NSInteger, UIPageViewControllerTransitionStyle) {
UIPageViewControllerTransitionStylePageCurl = 0, // Navigate between views via a page curl transition.书页翻页效果
UIPageViewControllerTransitionStyleScroll = 1// Navigate between views by scrolling.滚动效果
};
UIKIT_EXTERN NSString *const UIPageViewControllerOptionSpineLocationKey; UIPageViewControllerTransitionStylePageCurl时有效
UIKIT_EXTERN NSString *const UIPageViewControllerOptionInterPageSpacingKeyNS_AVAILABLE_IOS(6_0);UIPageViewControllerTransitionStyleScroll 时有效
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self createContentPages];
NSDictionary * options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationNone] forKey:UIPageViewControllerOptionInterPageSpacingKey];
self.pageController = [[UIPageViewController alloc]initWithTransitionStyle:(UIPageViewControllerTransitionStyleScroll) navigationOrientation:(UIPageViewControllerNavigationOrientationHorizontal) options:options];
pageController.dataSource = self;
[pageController.view setFrame:self.view.bounds];
ContentViewController * initialViewController = [self viewCintrollerAtIndex:0];
ContentViewController * endViewController = [self viewCintrollerAtIndex:1];
NSArray * viewControllers = [NSArray arrayWithObjects:initialViewController,nil];
[pageController setViewControllers:viewControllers direction:(UIPageViewControllerNavigationDirectionForward) animated:NO completion:nil];
[self addChildViewController:pageController];
[self.view addSubview:pageController.view];
[pageController didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)createContentPages{
NSMutableArray * pageStrings = [[NSMutableArray alloc]init];
for (int i = 1; i < 11; i ++) {
NSString * contentString = [[NSString alloc]initWithFormat:@"<html><head></head><body><h1>Chapter %d</h1><p>This is the page %d of content displayed using UIPageViewController in iOS 5.</p></body></html>",i,i];
[pageStrings addObject:contentString];
}
pageContent = [[NSArray alloc]initWithArray:pageStrings];
}
- (ContentViewController *)viewCintrollerAtIndex:(NSUInteger)index{
if ([self.pageContent count] == 0 || (index >= [self.pageContent count])) {
return nil;
}
ContentViewController * dataViewController = [[ContentViewController alloc]initWithNibName:@"ContentViewController" bundle:nil];
dataViewController.dataObject = [self.pageContent objectAtIndex:index];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
[dataViewController.view addGestureRecognizer:tap];
return dataViewController;
}
- (NSUInteger)indexOfViewController:(ContentViewController*)viewController{
return [self.pageContent indexOfObject:viewController.dataObject];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
NSUInteger index = [self indexOfViewController:(ContentViewController *)viewController];
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageContent count]) {
return nil;
}
return [self viewCintrollerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
NSUInteger index = [self indexOfViewController:(ContentViewController *)viewController];
if (index == 0 || (index == NSNotFound)) {
return nil;
}
index --;
return [self viewCintrollerAtIndex:index];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return 10;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
详情请参考http://blog.sina.com.cn/s/blog_7b9d64af0101c2zg.html
demo:http://code4app.com/search/UIPopoverController
UIPopoverBackgroundView 作为一个抽象基类必须被被继承然后重写一下几个方法:
+ (CGFloat)arrowHeight;
+ (CGFloat)arrowBase;
+ (UIEdgeInsets)contentViewInsets;
/* This method may be overridden to prevent the drawing of the content inset and drop shadow inside the popover. The default implementation of this method returns YES.
*/
+ (BOOL)wantsDefaultContentAppearance NS_AVAILABLE_IOS(6_0);
#import <UIKit/UIPrintError.h>输出错误处理
#import <UIKit/UIPrintFormatter.h>输出格式化
#import <UIKit/UIPrintInfo.h>打印信息
#import <UIKit/UIPrintInteractionController.h>可以把你想打印的内容在ios打印了
#import <UIKit/UIPrintPageRenderer.h>html转化为PDF
#import <UIKit/UIPrintPaper.h>打印处理
UIPrintFormatter时打印格式化的抽象基类: 展示 了传统的可打印的内容对象可以跨页边界。由于打印格式化,打印系统,可以自动打印与打印格式化的内容相关联的类型。以下为UIPrintFormatter的子类:
UISimpleTextPrintFormatter类的实例进行布局打印纯文本,可能是多个页面。类允许您指定的印刷文字全球的字体,颜色,对齐线,和换行符的模式属性。
UIMarkupTextPrintFormatter类的实例展示了一个多页打印作业的HTML标记文本。
UIViewPrintFormatter类的一个实例,勾画出用于打印的视图绘制的内容。视图的内容可以跨越多个页面。
一个UIPrintInfo对象封装了有关打印作业的信息,包括打印机标识,作业名称,输出类型(照片,正常,灰阶),方向(纵向或横向),和任何选定的双工模式,。打印系统打印时,使用此信息。
UIPrintInteractionController类的共享实例,提出了印刷的用户界面和管理的文件,图像和其他可打印的内容在iOS打印。UIPrintInteractionController是IOS中央印刷类。它的共享实例代表一个打印作业。打印作业,包括其印刷相关的信息和选项,如输出类型,作业名称,纸张大小和方向,要打印的内容。
一个UIPrintPageRenderer对象绘制要打印页的内容带或不带打印格式化.A页面的渲染就是UIPrintPageRenderer自定义子类的一个实例。当您撰写打印作业使用的UIPrintInteractionController共享实例,您指定的页面渲染到该实例的printPageRenderer属性。
UIPrintPaper类的一个实例封装使用的纸张尺寸,打印作业,并在其中的内容可以打印的矩形。
原文出处 http://hi.baidu.com/caoruifang/item/a2aade0837899f294bc4a357
NSString *str = @"apple";
if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:str] == YES)
{
UIReferenceLibraryViewController *reference =
[[[UIReferenceLibraryViewController alloc] initWithTerm:str] autorelease];
// Change the transition style
[reference setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:reference animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Popover Title";
self.refreshControl = [[UIRefreshControl alloc]init];
[self.refreshControl setTintColor:[UIColor blueColor]];
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
[self.refreshControl addTarget:self action:@selector(refreshAction) forControlEvents:UIControlEventValueChanged];
}
-(void)refreshAction
{
[self.refreshControl endRefreshing];
}
-》UIResponder Class Reference
Managing the Responder Chain
- 1.- (UIResponder *)nextResponder
UIResponder类不自动存储和设置下一个响应者,而是默认返回nil。子类必须override这个方法来设置下一个响应者。
UIView实现了这个方法,因为可以返回管理这个UIView的UIViewController或者它的父类;
UIViewController实现了这个方法,返回UIViewController的View的父View;
UIWindow发挥UIApplication对象;
UIApplication返回nil
- 2.- (BOOL)isFirstResponder
- 3.- (BOOL)canBecomeFirstResponder
如果一个响应对象通过这个方法返回YES,那么它成为了第一响应对象,并且可以接收触摸事件和动作消息。
子类必须overrider这个方法才可以成为第一响应者。
You must not send this message to a view that is not currently attached to the view hierarchy. The result is undefined.
- 3.- (BOOL)becomeFirstResponder
子类可以override这个方法来更新状态或者执行一些行为,比如高亮选中项。
一个响应对象只有当前响应者可以放弃第一响应者状态,并且新的响应者可以成为第一响应者,才能成为第一响应对象。
- 4.- (BOOL)canResignFirstResponder
- 5.- (BOOL)resignFirstResponder
如果返回NO,拒绝放弃第一响应状态。
如果你override这个方法,必须调用父类的实现[super resignFirstResponder].
Managing Input Views
- 1.@property (readonly, retain) UIView *inputView
This property is typically used to replace the system-supplied keyboard that is presented for UITextField and UITextView objects.
UITextField和UITextView如果设置了inputView那么在becomeFirstResponder时不会显示键盘,而现实自定义的inputView;如果设置了inputAccessoryView那么在becomeFirstResponder时会在键盘的顶端显示自定义的inputAccessoryView。
- 2.@property (readonly, retain) UIView *inputAccessoryView
This property is typically used to attach an accessory view to the system-supplied keyboard that is presented for UITextField and UITextViewobjects.
- 3.- (void)reloadInputViews
Responding to Touch Events
- 1.- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
将消息转发给下一个响应者,将消息发送给父类,不要将消息直接传递给下一个响应者。
如果你override这个方法而没有调用super..,你必须同样override其它响应触摸事件的方法,你要是空实现就好。
默认是不支持多点触摸的,如果想要响应多点触摸,你只要吧UIView的 multipleTouchEnabled 属性设置为YES即可。
- 2.- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
- 3.- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
- 4.- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
Responding to Motion Events
- 1.- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
- 2.- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
- 3.- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
Responding to Remote-Control Events
- 1.- (void)remoteControlReceivedWithEvent:(UIEvent *)event
Getting the Undo Manager
- 1.@property(readonly) NSUndoManager *undoManager
Validating Commands
- 1.- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
YES if the the command identified by action should be enabled or NO if it should be disabled. Returning YES means that your class can handle the command in the current context.
用于捕获蓝牙键盘的按键事件,例:
- - (NSArray *)keyCommands
- {
- return @[[UIKeyCommand keyCommandWithInput:@"f"
- modifierFlags:UIKeyModifierCommand
- action:@selector(searchKeyPressed:)]];
- }
- - (void)searchKeyPressed:(UIKeyCommand *)keyCommand
- {
- // Respond to the event
- }
- (CADisplayLink *)displayLinkWithTarget:(id)target selector:(SEL)sel NS_AVAILABLE_IOS(4_0);
CADisplayLink* gameTimer;
gameTimer = [CADisplayLink displayLinkWithTarget:self
selector:@selector(updateDisplay:)];
[gameTimer addToRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates NS_AVAILABLE_IOS(7_0); 截屏
10.UIScrollView
typedef NS_ENUM(NSInteger, UIScrollViewKeyboardDismissMode) {
UIScrollViewKeyboardDismissModeNone,
UIScrollViewKeyboardDismissModeOnDrag, // dismisses the keyboard when a drag begins
UIScrollViewKeyboardDismissModeInteractive, // the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss
} NS_ENUM_AVAILABLE_IOS(7_0);
pagingEnabled:当值是 YES 会自动滚动到 subview 的边界,默认是NO
touchesShouldCancelInContentView: 开始发送 tracking messages 消息给 subview 的时候调用这个方法,决定是否发送 tracking messages 消息到subview。假如返回 NO,发送。YES 则不发送。
假如 canCancelContentTouches属性是NO,则不调用这个方法来影响如何处理滚动手势。
scroll view 还处理缩放和平移手势,要实现缩放和平移,必须实现委托 viewForZoomingInScrollView:、scrollViewDidEndZooming:withView:atScale:
两个方法。另外 maximumZoomScale和minimumZoomScale 两个属性要不一样。
几个属性介绍
tracking
当 touch 后还没有拖动的时候值是YES,否则NO
zoomBouncing
当内容放大到最大或者最小的时候值是 YES,否则 NO
zooming
当正在缩放的时候值是 YES,否则 NO
delaysContentTouches
是个布尔值,当值是 YES 的时候,用户触碰开始,scroll view要延迟一会,看看是否用户有意图滚动。假如滚动了,那么捕捉 touch-down 事件,否则就不捕捉。假如值是NO,当用户触碰, scroll view 会立即触发 touchesShouldBegin:withEvent:inContentView:,默认是 YES
canCancelContentTouches
当值是 YES 的时候,用户触碰后,然后在一定时间内没有移动,scrollView 发送 tracking events,然后用户移动手指足够长度触发滚动事件,这个时候,scrollView 发送了 touchesCancelled:withEvent: 到 subview,然后 scroView 开始滚动。假如值是 NO,scrollView 发送 tracking events 后,就算用户移动手指,scrollView 也不会滚动。
contentSize
里面内容的大小,也就是可以滚动的大小,默认是0,没有滚动效果。
bounces
默认是 yes,就是滚动超过边界会反弹有反弹回来的效果。假如是 NO,那么滚动到达边界会立刻停止。
bouncesZoom
和 bounces 类似,区别在于:这个效果反映在缩放上面,假如缩放超过最大缩放,那么会反弹效果;假如是 NO,则到达最大或者最小的时候立即停止。
directionalLockEnabled
默认是 NO,可以在垂直和水平方向同时运动。当值是 YES 时,假如一开始是垂直或者是水平运动,那么接下来会锁定另外一个方向的滚动。 假如一开始是对角方向滚动,则不会禁止某个方向
indicatorStyle
滚动条的样式,基本只是设置颜色。总共3个颜色:默认、黑、白
scrollIndicatorInsets
设置滚动条的位置