回答
只需創建一個容器uiviewcontroller
,將有例如一個靜態按鈕和一個空的uiview
。創建它們作爲iboutlets和通常屬性UIPageViewController
稱爲pvc。然後你可以在代碼中創建一個pvc,並通過addSubview:
將它添加到uiview插座。
這是從我上個週末做的一個項目複製的一些代碼。在UIPageViewController
中有Skidata,並將一個雪花的UIImage
作爲覆蓋。我只複製了代碼的相關部分。希望這將幫助你:
SkiViewController.m
@interface SkiViewController() <UIPageViewControllerDataSource>
@property (strong, nonatomic) UIPageViewController *pageController;
@property (strong, nonatomic) SkiDataArray* skiDataArray;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIView *pageDataView;
@end
@implementation SkiViewController
- (SkiSubViewController *)viewControllerAtIndex:(NSUInteger)index
{
SkiSubViewController *childViewController = [[SkiSubViewController alloc] initWithNibName:@"SkiSubViewController" bundle:nil];
childViewController.indexNumber = index;
if(self.skiDataArray)
{
childViewController.skiData = self.skiDataArray[index];
}
return childViewController;
}
#pragma mark - lify cycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[self addPageControllerViewControllers];
[self addPageControllerView];
[self addChildViewController:self.pageController];
[self.pageController didMoveToParentViewController:self];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateData]; // download ski data and stuff
}
- (void)addPageControllerViewControllers
{
SkiSubViewController *viewController = [self viewControllerAtIndex:0];
if(self.skiDataArray)
{
viewController.skiData = self.skiDataArray[0];
}
[self.pageController setViewControllers:@[viewController] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
- (void)addPageControllerView
{
self.pageController.view.translatesAutoresizingMaskIntoConstraints = NO; // avoids conflicts with auto generated constraints
[self.pageDataView addSubview:self.pageController.view];
NSDictionary *views = @{ @"subview": self.pageController.view };
[self.pageDataView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[subview]|" options:0 metrics: 0 views:views]];
[self.pageDataView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[subview]|" options:0 metrics: 0 views:views]];
[self.pageDataView updateConstraintsIfNeeded];
}
#pragma mark - uipageviewcontroller data source
- (UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [(SkiSubViewController *)viewController indexNumber];
if (index == 0)
{
return nil;
}
else
{
index--;
return [self viewControllerAtIndex:index];
}
}
- (UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((SkiSubViewController *)viewController).indexNumber;
index++;
if (index == self.skiDataArray.count)
{
return nil;
}
else
{
return [self viewControllerAtIndex:index];
}
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return self.skiDataArray.count;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
@end
SkiSubViewController.h
@interface SkiSubViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (assign, nonatomic) NSInteger indexNumber;
@property (strong, nonatomic) SkiData* skiData;
@end
SkiSubViewController.m
@interface SkiSubViewController()
@property (weak, nonatomic) IBOutlet UILabel *label;
@end
@implementation SkiSubViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.label.text = [NSString stringWithFormat:@"Number %li", (long)self.indexNumber];
}
@end
請證明代碼是否可能以及何時可能。我試圖把'UIPageViewController().view'作爲子視圖放在'uiviewcontroller'容器中,但它對我不起作用。謝謝 – Arsen
好吧,我已經添加了一些代碼 – donmarkusi
你能否提供一個快速的例子。我無法在任何地方找到一個。 – Xitcod13
- 1. xamarin/mvvmcross帶有靜態內容的UITableView
- 2. 帶有混合靜態/動態內容的UITableViewController中的NSRangeException
- 3. 靜態內容
- 4. 靜態內容
- 5. 帶有靜態寬度容器的Flex
- 6. 帶有UIPageViewController的UIPopoverController不顯示任何內容
- 7. 帶有動態內容的jquery模態
- 8. 帶有靜態寬度的內聯div
- 9. Html.dropdownlist靜態內容
- 10. 帶動態內容的Java靜態窗口
- 11. 靜態內容的RouteHandler
- 12. 帶有動態內容的android佈局?
- 13. 帶有動態內容的Android ViewPager
- 14. 帶有框架的UIPageViewController
- 15. 帶有靜態行的CursorLoader
- 16. appharbor沒有部署靜態內容
- 17. 春天沒有加載靜態內容
- 18. 帶動態內容的JQuery
- 19. 帶動態內容的RowExpander
- 20. 靜態內容在Django
- 21. 服務靜態內容
- 22. Jetty.xml訪問靜態內容
- 23. 快速gzip靜態內容
- 24. nginx重寫靜態內容
- 25. ASP.NET MVC:靜態內容
- 26. 處理靜態內容(CSS)
- 27. i18n靜態HTML內容
- 28. 過濾靜態內容Jersey
- 29. Liferay - 發送靜態內容
- 30. Spring:DispatcherServlet和靜態內容
你可以添加一個圖像或場景來闡明你的想法嗎? – donmarkusi
@donmarkusi請檢查出 – Arsen