簡體   English   中英

簡單的庫,用於視圖控制器之間的交互式滑動過渡

[英]Simple library for interactive swipe transitions between view controllers

如標題所示,我正在尋找一個簡單的庫,我可以使用該庫來允許用戶在視圖控制器之間交互滑動(請記住,我的應用程序沒有導航控制器)。 我知道在SO上已經有幾個不同的問題可以回答這個問題,但是我知道大多數問題都已經很老了,我想知道iOS 7是否有更簡單的解決方案可用。 我花了幾天時間嘗試實現不同的方法,但是在每種情況下,我的代碼都太混亂了,並充滿了各種錯誤。 順便說一句,我所有的談話都是模態的(如果有什么用?)。

簡單來說,我是指一個獨立的庫,可以從手勢識別器中調用它,而這正是該特定視圖控制器所需要的

-(void)hasswipedright:(UIGestureRecognizer*)Gesture{
//Library Creates transition between this VC and another VC
}

我嘗試調查以下嘗試:

我將使用UIScrolView或UIPageContainer,但我認為這不會起作用,因為我只想將視圖控制器之間的某些跳轉設計為“可交換”(即B可以滑動到A,但不能以其他方式滑動,但是A可以滑動到C和D,反之亦然)。

有什么建議么? 我希望使過渡具有交互性(類似於在iOS7的Safari中向后移動所需的pangesturerecognizer之類的東西)。 任何評論都非常感謝。 我不想懶洋洋地要求圖書館,只是我沒有時間手動重新格式化所有內容(而且,我只是iOS開發的初學者!)

非常感謝!

https://github.com/cwRichardKim/RKSwipeBetweenViewControllers

簽出功能“被拖曳”或類似的功能。 您有兩個選擇。 您可以設置一個pageviewcontroller,然后使用委托方法(它們在該存儲庫中以及在底部附近)來指示前后出現的視圖控制器,因此您可以檢查每次滑動時要執行的操作,或者可以從pageviewcontroller中獲取滾動視圖本身(請參見方法“ syncscrollview”),然后將自定義方法(在這種情況下為dragd)添加到識別的手勢。 然后,您可以應用邏輯以確保使用正確的視圖控制器

這可以幫助您YZSwipeBetweenViewController

查看此倉庫可能會有所幫助。

它可幫助您創建一個Controller,在該Controller中,一個UiTableViewCell持有一個帶有可滾動節頭的UiPageViewController來更改viewController,並且還會擦除這些viewControllers。

在此處輸入圖片說明

https://github.com/iossolutions/PBSwipeController

添加這些對象並在viewdidload方法中初始化:-

    HeadingArray = @[@"Counting",@"Alphabets",@"Colors",@"Random",@"Names"];
    NSArray *array1 = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10"];
    NSArray *array2 = @[@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z"];
    NSArray *array3 = @[@"White",@"Orange",@"Blue",@"Green",@"Yellow"];
    NSArray *array4 = @[@"p",@"q",@"r",@"s",@"t"];
    NSArray *array5 = @[@"Abhi",@"Kabhi",@"Jabhi",@"Ravi",@"Lavi"];
    dataArray = [[NSMutableArray alloc]initWithObjects:array1,array2,array3,array4,array5, nil];

    [self addInitialObjects];
    [self setupSelector];}
    -(void)addInitialObjects{

    // Add Scroolable object in section header
    self.currentPageIndex = 0;
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,40)];
    _scrollView.backgroundColor = [UIColor colorWithRed:30.0f/255.0f green:144.0f/255.0f blue:255.0f/255.0f alpha:1];
    for (int i = 0; i<HeadingArray.count; i++) {
        UIButton  *button = [[UIButton alloc]init];
        button.frame = CGRectMake(i*100, 0, 100, 40);
        [_scrollView addSubview:button];
        button.tag = i;
        button.backgroundColor = [UIColor clearColor];
        [button addTarget:self action:@selector(tapSegmentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitle:[HeadingArray objectAtIndex:i] forState:UIControlStateNormal];
        button.titleLabel.textColor = [UIColor blackColor];
    }
    CGRect contentRect = CGRectZero;
    for (UIView *view in _scrollView.subviews) {
        contentRect = CGRectUnion(contentRect, view.frame);
    }
    _scrollView.contentSize = contentRect.size;

    // Page view controller for swipeable view
    UIPageViewController *pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
    navigationController = [[PBSwipeController alloc]initWithRootViewController:pageController];
    navigationController.swipeDelegate = self;
    [self addChildViewController:navigationController];
    [navigationController didMoveToParentViewController:self];
}    

在您的單元格中的索引行傳遞數據:-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell1 == nil) {
        cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    if (indexPath.section==0) {
        cell1.textLabel.text = @"Cell - Below is section header";
        cell1.backgroundColor = [UIColor colorWithRed:0.0f/255.0f green:255.0f/255.0f blue:127.0f/255.0f alpha:1];
    }
    else {
        cell1.textLabel.text = @"";
        cell1.backgroundColor = [UIColor clearColor];
        navigationController.pagesNameArray = HeadingArray;
        navigationController.pageDataArray = dataArray;
        [navigationController viewControllerAtIndex:0];
        [cell1.contentView addSubview:navigationController.view];
    }
    return cell1;
}

您可以使用此存儲庫。對於RnD來說,它是如此簡單和容易理解。 (快速3碼)

https://github.com/lakshikabhardwaj/LBViewControllerCollection

let catVC =   CatVC(nibName: "catVC", bundle: nil)    //UIViewController Objects
let cowVC =   CowVC(nibName: "CowVC", bundle: nil)
let elephantVC = ElephantVC(nibName: "ElephantVC", bundle: nil)
let chatVC =   ChatVC(nibName: "ChatVC", bundle: nil)

    let mainViewController = CPPageMenuVC(nibName: "CPPageMenuVC", bundle: nil)

let pageMenuarray :[PageModal] = [PageModal(pageTitle: "Cat", pageVC: catVC),PageModal(pageTitle: "Cow", pageVC: cowVC),PageModal(pageTitle: "Chat", pageVC: chatVC),PageModal(pageTitle: "ElephantElephant", pageVC: elephantVC)]
        pageMenuVC.pageArray = pageMenuarray

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM