久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

設(shè)置 UIScrollView 在 3 個視圖控制器之間滑動

Setting up UIScrollView to swipe between 3 view controllers(設(shè)置 UIScrollView 在 3 個視圖控制器之間滑動)
本文介紹了設(shè)置 UIScrollView 在 3 個視圖控制器之間滑動的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試設(shè)置 UIScrollView,以便可以在 3 個視圖控制器之間滑動.這是我在 AppDelegate.m 中的代碼:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];//應(yīng)用程序啟動后自定義的覆蓋點(diǎn).;UIScrollView *sv = [[UIScrollView alloc] init];BarsViewController *bvc = [[BarsViewController alloc] init];//創(chuàng)建 BarsViewControllerStopwatchViewController *svc = [[StopwatchViewController alloc] init];//創(chuàng)建 StopwatchViewControllerTimerViewController *tvc = [[TimerViewController alloc] init];//創(chuàng)建 TimerViewController[sv addSubview:bvc.view];[sv addSubview:svc.view];[sv addSubview:tvc.view];[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];//隱藏狀態(tài)欄self.window.rootViewController = sv;[self.window makeKeyAndVisible];返回是;}

它在這一行給出一個錯誤:

self.window.rootViewController = sv;

說,不兼容的指針類型從 UIScrollView * 分配給 'UIViewController *'".

但是,沒有 UIScrollViewController 這樣的東西,所以我不知道該怎么做.

基本上,我只想讓整個屏幕成為一個滾動視圖,讓我可以在我的 3 個視圖控制器之間滑動.我該怎么做呢?

解決方案

UPD:2015 年 6 月斯威夫特

這個概念保持不變,這在下面的 Objective-C 部分中進(jìn)行了描述.語法有一點(diǎn)變化.要添加 childviewcontroller,請使用以下代碼段:

讓 aViewController = storyboard.instantiateViewControllerWithIdentifier("A") as!視圖控制器;addChildViewController(aViewController);scrollView!.addSubview(aViewController.view)aViewController.didMoveToParentViewController(self)

查看我的

I am trying to set up a UIScrollView so that I can swipe between my 3 view controllers. This is my code in AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.;

UIScrollView *sv = [[UIScrollView alloc] init];

BarsViewController *bvc = [[BarsViewController alloc] init]; // Create BarsViewController
StopwatchViewController *svc = [[StopwatchViewController alloc] init]; // Create StopwatchViewController
TimerViewController *tvc = [[TimerViewController alloc] init]; // Create TimerViewController

[sv addSubview:bvc.view];
[sv addSubview:svc.view];
[sv addSubview:tvc.view];

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade]; // Hide status bar

self.window.rootViewController = sv;
[self.window makeKeyAndVisible];
return YES;
}

It gives an error on this line:

self.window.rootViewController = sv;

saying, "Incompatible pointer types assigning to 'UIViewController *' from UIScrollView *'".

However, there is no such thing as a UIScrollViewController, so I don't know what to do.

Basically, I just want the whole screen to be a scroll view which allows me to swipe between my 3 view controllers. How would I go about doing that?

解決方案

UPD: June, 2015 Swift

The concept remains the same, which is described below in Objective-C section. There is a little change in syntax. To add childviewcontroller use following snippet:

let aViewController = storyboard.instantiateViewControllerWithIdentifier("A") as! AViewController;

addChildViewController(aViewController);
scrollView!.addSubview(aViewController.view)
aViewController.didMoveToParentViewController(self)

Check my Swift Github Sample Code

Objective-C

Create your own custom container view controller (I will call it combinedViewController), which will hold your three controllers in scroll view. Inherit like you always do UIViewController, then use addChildViewController public API in your new combinedViewController -viewDidLoad: like this:

[self addChildViewController:aViewController];
[self.scrollView addSubview:aViewController.view];
[aViewController didMoveToParentViewController:self];

Here’s what the code does:

  • It calls the container’s addChildViewController: method to add the child.
  • It accesses the child’s view property to retrieve the view and adds it to its own view hierarchy. The container sets the child’s size and position before adding the view; containers always choose where the child’s content appears.
  • It explicitly calls the child’s didMoveToParentViewController: method to signal that the operation is complete.

Do this operation with each of your viewControllers. Afterwards, set your combinedViewController as a rootViewController.

if you need further explanation, feel free to ask.

Reference: Design custom container view controller

Here you are my Objective-C Github sample code

UPD: Thanks @Oliver Atkinson for clarifying that addChildViewController: method also calls the child’s willMoveToParentViewController: method automatically.

Results:

這篇關(guān)于設(shè)置 UIScrollView 在 3 個視圖控制器之間滑動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
UIScrollView with quot;Circularquot; scrolling(帶有“圓形的 UIScrollView滾動)
主站蜘蛛池模板: 呦呦在线视频 | 亚洲美乳中文字幕 | 蜜桃一区二区三区在线 | 国产精品久久久久久久午夜片 | 亚洲成人免费 | 久久久久国产精品www | 9色视频在线 | 一区二区三区小视频 | 精品亚洲一区二区三区 | 久久aⅴ乱码一区二区三区 亚洲欧美综合精品另类天天更新 | 国产精品视频一区二区三区四蜜臂 | 国产精品乱码一区二三区小蝌蚪 | 日本超碰| 亚洲一区二区三区福利 | 91精品国产一区二区三区香蕉 | 天天操天天摸天天爽 | 亚洲天堂中文字幕 | 草草视频在线观看 | 男女搞网站 | 日韩视频在线免费观看 | aaa国产大片 | 久久久久久久久久久久久91 | 国产免费一二三区 | 在线免费小视频 | 国内精品久久精品 | 国产乱精品一区二区三区 | 成人免费视频观看视频 | 日韩在线观看视频一区 | 国产一区二区在线免费观看 | 99福利视频导航 | 久草免费在线视频 | 中文字幕 在线观看 | 欧美一级做性受免费大片免费 | 久久精品毛片 | 成人性生交大片免费看r链接 | 免费在线观看黄色av | 免费精品视频在线观看 | 日韩手机视频 | 国产精品亚洲一区二区三区在线 | 1区2区3区视频 | 日日日色 |