移动开发:初学iOSUIViewController心得OneAPM官方技术博客

初学iOS,本文翻译了一些iOS官网上的UIViewController的知识点,如有不到位或不正确的地方,还请指正:

本文所介绍的内容的目标:

这是一个UIViewController

两个原因

设计模式

系统视图控制器通包括以下5种

Tableviewcontroller:表视图控制器Detailcontroller:详细控制器SVC:SSLVPNClient

根视图控制器真的可以管理“整个屏幕里显示的内容”么?

window.rootViewController=RootViewController

自定义视图控制器

Appearancecallbacks

(void)viewWillAppear:(void)viewDidAppear:(void)viewWillDisappear:(void)viewDidDisappear:Rotationcallbacks

(void)viewWillRotateToInterfaceOrientation:duration:(void)viewWillAnimateRotationToInterfaceOrientation:(void)viewDidRotateFromInterfaceOrientation:也许在iPhone上很少要关心的屏幕旋转问题的,但是大屏幕的iPad上就不同了,很多时候你需要关心横竖屏。rotationcallbacks一般情况下只需要关心三个方法:willRotateToInterfaceOrientation:duration:在旋转开始前,此方法会被调用;willAnimateRotationToInterfaceOrientation:duration:此方法的调用在旋转动画block的内部,也就是说在此方法中的代码会作为旋转animationblock的一部分;didRotateFromInterfaceOrientation:此方法会在旋转结束时被调用。而作为viewcontrollercontainer就要肩负起旋转的决策以及旋转的callbacks的传递的责任。

总结

了解视图控制器容器

两个层次的故事

蓝色:视图颜色蓝色箭头:子视图关系

金色:视图控制器颜色灰色箭头:父视图控制器关系

层次关系

API和控制器层次

(void)addChildViewController:(UIViewController*)childController;(void)removeFromParentViewController;@property(nonatomic,readonly)NSArray*childViewControllers;(void)willMoveToParentViewController:(UIViewController*)parent;(void)didMoveToParentViewController:(UIViewController*)parent;视图控制器容器层次关系

不一致的层次结构

UIViewControllerHierarchyInconsistencyException为什么会这么糟糕?

[selfaddChildViewController:note];//Transitiontonotecontrollerwithafliptransitionwhichadds//tnenoteviewtothewindowhierarchyandremovestherecipeview.[selftransitionFromViewController:recipetoViewController:noteduration:.5options:UIViewAnimationOptionTransitionFlipFromRightanimations:nilcompletion:^(BOOLfinished){[notedidMoveToParentViewController:self];}];[selfaddChildViewController:note];//Transitiontonotecontrollerwithafliptransitionwhichadds//tnenoteviewtothewindowhierarchyandremovestherecipeview.[selftransitionFromViewController:recipetoViewController:noteduration:.5options:UIViewAnimationOptionTransitionFlipFromRightanimations:nilcompletion:^(BOOLfinished){[notedidMoveToParentViewController:self];}];视图控制器容器API和控制器层次

-(void)transitionFromViewController:(UIViewController*)fromVCtoViewController:(UIViewController*)toVCduration:(NSTimeInterval)durationoptions:(UIViewAnimationOptions)optionsanimations:(void(^)(void))animationscompletion:(void(^)(BOOLfinished))completion;-(void)viewWillLayoutSubviews-(void)viewDidLayoutSubviews连接流——打开和关闭屏幕时获取视图控制器

Containers(容器)

-(void)pushViewController:animated:-(void)popViewControllerAnimated:Presentationanddismissal

-(void)presentModalViewController:animated:-(void)dismissModalViewControllerAnimated:

-(void)presentViewController:(UIViewController*)vcanimated:(BOOL)animatedcompletion:(void(^)(void))completion;-(void)dismissViewControllerAnimated:(BOOL)animatedcompletion:(void(^)(void))completion;

-(UIViewController*)parentViewController;-(UIViewController*)presentingViewController;

视图操作

[root.someViewaddSubview:vc.view]

[rootVCaddChildViewController:vc]

inception(启动)

inception(启动)仅在iPad上

@protocolUISplitViewControllerDelegate...//ReturnsYESifaviewcontrollershouldbehiddenby//thesplitviewcontrollerinagivenorientation.//(Thismethodisonlycalledontheleftmostviewcontroller//andonlydiscriminatesportraitfromlandscape.)-(BOOL)splitViewController:(UISplitViewController*)svcshouldHideViewController:(UIViewController*)vcinOrientation:(UIInterfaceOrientation)orientation;@end设计一个新的应用程序流为修正一个食谱应用创建一个应用程序流

ContainerViewControllerDemo

演示亮点——容器的移动

-(IBAction)flipToNote{if(...){...[selfaddChildViewController:_noteController];[selftransitionFromViewController:_contentControllertoViewController:_noteControllerduration:.5options:UIViewAnimationOptionTransitionFlipFromRightanimations:nilcompletion:^(BOOLfinished){_flipNoteButton.title=@"HideNote";_flipNoteButton.action=@selector(flipFromNote);[_noteControllerdidMoveToParentViewController:self];}];}}-(IBAction)flipFromNote{if(_isNoteBeingShown){[_noteControllerwillMoveToParentViewController:nil];[selftransitionFromViewController:_noteControllertoViewController:_contentControllerduration:0.5options:UIViewAnimationOptionTransitionFlipFromLeftanimations:nilcompletion:^(BOOLfinished){_flipNoteButton.title=@"ShowNote";_flipNoteButton.action=@selector(flipToNote);[_noteControllerremoveFromParentViewController];_isNoteBeingShown=NO;}];}}

Movinginandoutofcontainers

-(void)viewDidAppear:(BOOL)animated{[superviewDidAppear:animated];if(![selfisMovingToParentViewController]){[[selfparentViewController]updateSelectionForListOfContentIdentifiersIfNecessary];}}inception(启动)

-(BOOL)isMovingToParentViewController;//Usedinappearancecallbacks-(BOOL)isMovingFromParentViewController;//Usedindisappearancecallbacks-(BOOL)isBeingPresented;-(BOOL)isBeingDismissed;-(BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers;-(IBAction)flipToNote{if(...){...[selfaddChildViewController:_noteController];[_noteControllerviewWillAppear:YES];//Somefancyanimationthatculminatesintheviewswap//E.g[[_contentController.viewsuperview]addSubview:_noteController.view];...//Finallythisisusuallycalledinacompletionhandler//aftertheanimationcompletes[_noteControllerviewDidAppear:YES];[_noteControllerdidMoveToParentViewController:self];}}容器视图控制器示例为修正一个食谱应用创建一个应用程序流演示亮点——定义演示文稿上下文

-(IBAction)emailContent{UIViewController*presenter=_isNoteBeingShown_noteController:_contentController;...mailController.modalPresentationStyle=UIModalPresentationCurrentContext;if(_contentController&&[MFMailComposeViewControllercanSendMail]){...data=[_contentProviderdataForContentIdentifier:self.contentControllerIdentifiermimeType:&mimeType];note=[_contentProvidernoteForContentIdentifier:self.contentControllerIdentifier];...[presenterpresentViewController:mailControlleranimated:YEScompletion:^{[mailControllerrelease];}];}}

mc.modalPresentationStyle=UIModalPresentationCurrentContext;[rbpresentViewController:mailControlleranimated:YEScompletion:^{...}];

mc.modalPresentationStyle=UIModalPresentationCurrentContext;[notepresentViewController:mailControlleranimated:YEScompletion:^{...}

-(void)viewDidLoad{[superviewDidLoad];self.view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;self.definesPresentationContext=YES;...}@property(nonatomic,assign)BOOLdefinesPresentationContext;//Acontrollerthatdefinesthepresentationcontextcanalso//specifythemodaltransitionstyleifthispropertyistrue.@property(nonatomic,assign)BOOLprovidesPresentationContextTransitionStyle;视图控制器容器总结

导航与视图之间的页面卷曲过渡

一个容器视图控制器

Initialization(初始化)

-initWithTransitionStyle:navigationOrientation:options:UIPageViewController*myPVC=[[UIPageViewControlleralloc]initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurlnavigationOrientation:UIPageViewControllerNavigationOrientationHorizontaloptions:[NSDictionarydictionaryWithObjectsAndKeys:[NSNumbernumberWithInteger:UIPageViewControllerSpineLocationMid],UIPageViewControllerOptionSpineLocationKey]]初始视图控制器

-setViewControllers:direction:animated:completion:[myPVCsetViewControllers:[NSArrayarrayWithObjects:firstVC,secondVC,nil]direction:UIPageViewControllerNavigationDirectionForwardanimated:NOcompletion:nil];编程导航

[myPVCsetViewControllers:[NSArrayarrayWithObjects:thirdVC,fourthVC,nil]direction:UIPageViewControllerNavigationDirectionForwardanimated:NOcompletion:nil]YES^(BOOLfinished){NSLog(@"Pagecurlcompleted.");}];[myPVCsetViewControllers:[NSArrayarrayWithObjects:thirdVC,fourthVC,nil]direction:UIPageViewControllerNavigationDirectionForwardanimated:completion:YES^(BOOLfinished){NSLog(@"Pagecurlcompleted.");}];

THE END
1.什么是四川胡椒的定义和食谱四川辣椒的特色包括棒棒鸡(棒棒鸡),丹丹面,宫保鸡和麻婆豆腐等。 食谱频繁呼吁四川 花椒磨碎并烘烤。 磨碎的四川胡椒粉用来制作浸泡过的油,并与盐配成调味料。 四川花椒是构成五香粉的五种成分之一(其他是八角茴香,茴香丁香和肉桂)。 如何存储四川胡椒粉或地面四川胡椒粉? https://zhcn.hiloved.com/%E4%BB%80%E4%B9%88%E6%98%AF%E5%9B%9B%E5%B7%9D%E8%83%A1%E6%A4%92%E7%9A%84%E5%AE%9A%E4%B9%89%E5%92%8C%E9%A3%9F%E8%B0%B1/
2.什么是食谱,名词解释定义是?名词解释 食谱 参考答案:某种鱼消化道中所有饵料生物的总称。 点击查看答案进入题库练习 查答案就用赞题库小程序 还有拍照搜题 语音搜题 快来试试吧 无需下载 立即使用 你可能喜欢 名词解释 食物链与食物网 参考答案: 生态系统中,各种生物之间所形成的一连串的食物关系称为食物链;由许多食物环节彼此交错互相https://m.ppkao.com/mip/tiku/shiti/6349294.html
3.分期消费的定义是什么其他 二型糖尿病人食谱是什么 二型糖尿病人食谱之一绿茶鸭蛋:鸭蛋滋阴润燥,绿茶清热止渴。经常小吃,或佐餐食用本品,有辅助治疗糖尿病 2021-01-15 其他 眼膜贴完要用眼霜吗 1、要根据个人的情况决定。因为每个人的肤质都是不一样的,所以在贴完眼贴膜之后,是否还需要使用眼霜,要根据个人的皮肤情况决定,如http://m.qicaisi.com/bk-82583.shtml
4.慢性荨麻疹食谱徐学超医生的语音科普慢性荨麻疹食谱 徐学超主治医师 中国人民解放军第107医院皮肤性病科 2018-09-244019次 00:00 1:20 医生主讲实录 慢性荨麻疹定义是指每周发作两次或者两次以上持续时间达到42天以上,我们称之为慢性荨麻疹,慢性荨麻疹患者原因也是比较难找。 饮食上我们也是应该注意,否则使病情加重或者是难以恢复正常。饮食上首先我们https://www.miaoshou.net/voice/324830.html
5.人工受孕和试管婴儿有什么不同专家文章人工受孕,还有试管婴儿是两种不同的治疗不孕不育的方法,这两种方法是效率最高的,而且也受到了很多患者的欢迎,很多患者会将这两种治疗方式混为一种。那么,人工受孕和试管婴儿有什么不同? 1、两者定义不同 人工受孕是通过人工将精液助于女性的宫腔中,以保证尽快的受孕,试管婴儿则是体外受精,分别将卵子,还有精子取出https://www.bohe.cn/article/view/159457.html
6.模组汉化分享ONI美食食谱1.首先下载最新版食谱的主mod2.其次下载这个作者出的各式菜品 3.最后将我的汉化mod跟上面两个放在一起 备注:本体只放了原链接,汉化是网盘打包的,下载地址都放在最后了。/这个自定义美食mod可以在厨房-微波炉分类里找到。如果点开没有任何菜单可能是你的厨艺/烘焙/美食技能不够 https://www.douban.com/group/topic/283821718/
7.eycloud从EY Cloud 页面下载ey-cloud.yml文件并将其放在您的HOME目录?/ .ey-cloud.yml中 安装所需的gem:sudo gem install rest-client aws-s3 sudo gem install ey-flex --source //gems.engineyard.com#确保您使用的是最新版本 将任何自定义食谱或tweeks添加到您自己的基本食谱中,然后将其提交给HEAD。 使用以下https://download.csdn.net/download/weixin_42132352/16239129