我想構建像這些圖片中顯示的滑動導航。總共有4個標題水平放置。如何在iOS中創建滑動導航(在Objective-C中)
它們如下。
- 「歷史」
- 「規則」
- 「PRO」
- 「條款和條件」
如果我讀 「歷史」 從右至左&輕掃,然後應顯示「規則」。
如果上午「實施細則」,並從刷卡左到右,那麼它應該顯示「歷史」
任何人都可以請指導我如何做到這一點?
謝謝。
我想構建像這些圖片中顯示的滑動導航。總共有4個標題水平放置。如何在iOS中創建滑動導航(在Objective-C中)
它們如下。
如果我讀 「歷史」 從右至左&輕掃,然後應顯示「規則」。
如果上午「實施細則」,並從刷卡左到右,那麼它應該顯示「歷史」
任何人都可以請指導我如何做到這一點?
謝謝。
您發佈的鏈接是靜態截圖,並且對描述您想要執行的操作沒有太大幫助。
我認爲你所描述的是一個UIPageViewController
的正常行爲,爲幻燈片轉換而不是頁面捲曲轉換設置。
在Xcode中搜索「PhotoScroller」。這將指向一個演示應用程序,說明我認爲你以後的效果。該應用程序比您需要的更復雜,因爲它支持縮放和平鋪圖片渲染,但您可以忽略這些內容。
謝謝@duncan .....我會檢查UIPageViewController。並不知道如何創建動畫GIF。今後,如果有必要,我會上傳動畫GIF。再次感謝:) –
我也會推薦一個UIPageViewController。這裏是一個裸骨執行:
@interface SwipeViewController : UIViewController <UIPageViewControllerDataSource>
@property (nonatomic, strong) UIPageViewController *pageViewController;
@property (nonatomic, strong) NSArray <UIViewController*> *viewControllers;
@end
@implementation SwipeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// add page view controller
[self.pageViewController willMoveToParentViewController:self];
[self.view addSubview:self.pageViewController.view];
[self addChildViewController:self.pageViewController];
[self.pageViewController didMoveToParentViewController:self];
// set the first view controller as the displayed view controllers (requires an array of exactly one view controller)
[self.pageViewController setViewControllers:@[self.viewControllers.firstObject] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
// array of 4 random colored view controllers
- (NSArray <UIViewController*>*)viewControllers {
if (!_viewControllers) {
_viewControllers = ({
NSMutableArray *viewControllers = [NSMutableArray new];
for (int i = 0; i < 4; i++) {
UIViewController *aViewController = [UIViewController new];
aViewController.view.backgroundColor = [UIColor colorWithRed:(arc4random()%255)/255. green:(arc4random()%255)/255. blue:(arc4random()%255)/255. alpha:1];
[viewControllers addObject:aViewController];
}
viewControllers;
});
}
return _viewControllers;
}
- (UIPageViewController *)pageViewController {
if (!_pageViewController) {
_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
_pageViewController.dataSource = self;
}
return _pageViewController;
}
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSInteger index = [self.viewControllers indexOfObject:viewController];
return index > 0 ? self.viewControllers[index-1] : nil;
}
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSInteger index = [self.viewControllers indexOfObject:viewController];
return index + 1 < self.viewControllers.count ? self.viewControllers[index+1] : nil;
}
@end
謝謝@casey ...我會在幾個小時內嘗試這個,然後回來。 –
這正是你想要的。 https://github.com/maxep/MXSegmentedPager – iOSEnthusiatic
使用故事板示例更容易實現。 – iOSEnthusiatic
謝謝@Rushisangani .....多數民衆贊成我正在尋找。 –