Ios UIPageviewController在其自身视图顶部随机显示视图

Ios UIPageviewController在其自身视图顶部随机显示视图,ios,objective-c,arrays,uiview,uipageviewcontroller,Ios,Objective C,Arrays,Uiview,Uipageviewcontroller,我实际上在建一个旋转木马。我的目标是使其通用化,这意味着我希望它能够接收控制器阵列,并且仅使用创建旋转木马的控制器(将UIPageViewController以与阵列相同的顺序显示控制器的计数固定) 到目前为止,我构建的是接收控制器阵列的控制器,以及构建基本屏幕的通用控制器 管理阵列中页面的控制器是: bRGenericonboarding (.h) 这就是我所说的入职培训: - (void)createOnboarding { // Onboarding Screens p

我实际上在建一个旋转木马。我的目标是使其通用化,这意味着我希望它能够接收控制器阵列,并且仅使用创建旋转木马的控制器(将UIPageViewController以与阵列相同的顺序显示控制器的计数固定)

到目前为止,我构建的是接收控制器阵列的控制器,以及构建基本屏幕的通用控制器

管理阵列中页面的控制器是:

bRGenericonboarding

(.h)

这就是我所说的入职培训:

- (void)createOnboarding {

    //  Onboarding Screens
    pag1ViewController *vc1 = [[pag1ViewController alloc] init];
    pag2ViewController *vc2 = [[pag2ViewController alloc] init];
    BSRComodinesSuperClubOnboardingScreen1 *vc3 = [[BSRComodinesSuperClubOnboardingScreen1 alloc] init];

     self.vc = [[BSRGenericOnboarding alloc] initWithArrayOfControllers:[[NSArray alloc] initWithObjects:vc1, vc2, vc3,nil]
                                                                    andCallerController:self];

    self.vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    [self presentViewController:self.vc animated:NO completion:nil];
}
问题在于,当我滚动旋转木马的第一页时,有时下一页(前页)会随机出现在所有视图的前面,如下图所示:

我搜索了好几天,但我自己无法解决这个问题,这是我唯一能解决的问题,有时当调用方法pageViewController:viewControllerAfterViewController:和pageViewController:ViewControllerBeforReviewController:时,它们会带来前视图,但在旋转木马的顶部,同时显示两个视图,正如照片所描述的

我想知道如何解决这个问题,以及是否有更简单的方法来完成我所做的事情

非常感谢您的阅读

#import "BSRGenericOnboarding.h"
#import "BSRGenericOnboardingScreenViewController.h"
#import "BaseViewController.h"
#import "BSROnboardingCarouselButton.h"

#import "Constants.h"// Import screen measures and constants


@interface BSRGenericOnboarding ()

@property (nonatomic, weak)     BaseViewController      *BVC;//  contains the caller of this object

@property (nonatomic, strong)   UIPageViewController    *UIPageCV;

@end

@implementation BSRGenericOnboarding

#pragma mark - init

//  INIT
- (instancetype)initWithArrayOfControllers:(NSArray *)arrayOfControllers
                       andCallerController:(BaseViewController *)callerController {

    self = [super init];

    if (self) {

        self.pantallas = [arrayOfControllers copy]; // getting screens!
        self.BVC = callerController;
    }

    return self;
}

#pragma mark - view Lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];

    //  add a self reference to screens
    [self addSelfToScreens];

    //  Init UIPageViewCotroller
    self.UIPageCV = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
                                                    navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                                                                  options:nil];

    self.view.backgroundColor           = [UIColor clearColor];
    self.UIPageCV.view.backgroundColor  = [UIColor clearColor];
    self.UIPageCV.delegate = self;
    self.UIPageCV.dataSource = self;
    [[self.UIPageCV view] setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

    [self.UIPageCV setViewControllers:@[self.pantallas[0]]
                            direction:UIPageViewControllerNavigationDirectionForward
                             animated:NO
                           completion:nil];

    [self addChildViewController:self.UIPageCV];
    [self.view addSubview:self.UIPageCV.view];
    [self.UIPageCV didMoveToParentViewController:self];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UIPageViewControllerDelegate

- (void)pageViewController:(UIPageViewController *)pageViewController
willTransitionToViewControllers:(NSArray<UIViewController *> *)pendingViewControllers {


}

#pragma mark - UIPageViewControllerDataSource

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
       viewControllerAfterViewController:(UIViewController *)viewController {

    for(int i=0;i<self.pantallas.count ;i++)
    {
        if(viewController == [self.pantallas objectAtIndex:i])
        {
            if(i+1 < self.pantallas.count)
            {
                return [self.pantallas objectAtIndex:i+1];
            }
        }
    }

    return nil;
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
      viewControllerBeforeViewController:(UIViewController *)viewController {

    for(int i=0;i<self.pantallas.count ;i++)
    {
        if(viewController == [self.pantallas objectAtIndex:i])
        {
            if(i-1 >= 0)
            {
                return [self.pantallas objectAtIndex:i-1];
            }
        }
    }

    return nil;
}

#pragma mark - UIPageViewController Utils

//  Cierra el onboarding
- (void)dismissOnboarding {

    [self dismissViewControllerAnimated:NO completion:nil];
}


- (void)addSelfToScreens {

    for (BSRGenericOnboardingScreenViewController *screen in self.pantallas) {

        screen.onboardingUIPageVC = self;
    }
}

@end
#define INDEXDOTHIGH 15    //index button high
#define INDEXDOTWIDTH 15   //index button width
#define ESPACIADO 4        //index buttons spacing

#import <UIKit/UIKit.h>

#import "BSRGenericOnboarding.h"
#import "BSROnboardingCarouselBar.h"

@interface BSRGenericOnboardingScreenViewController : UIViewController

//contains the reference to the BSRGenericOnboarding
@property (nonatomic, weak) BSRGenericOnboarding      *onboardingUIPageVC;

//contains the reference of the object caller of BSRGenericOnboarding
@property (nonatomic, weak) BaseViewController    *BVC;


@property (nonatomic, strong) BSROnboardingCarouselBar  *buttonsBar;

//Hide buttons bar
- (void)hideCasrousel;

//Show buttons bar
- (void)unhideCasrousel;

@end
#import "BSRGenericOnboarding.h"
#import "BSRGenericOnboardingScreenViewController.h"
#import "BSROnboardingCarouselBar.h"
#import "Constants.h" // Constantes de tamano de pantalla

@interface BSRGenericOnboardingScreenViewController ()

@property (nonatomic, strong) UIView                    *backScreen;//  black screen for behind

@end

@implementation BSRGenericOnboardingScreenViewController

#pragma mark - View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [[[UIApplication sharedApplication] keyWindow] addSubview:self.view];

    [self setCarouselBar];

    self.backScreen = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.backScreen.alpha = 0.9;
    self.backScreen.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.backScreen];
    [self.view sendSubviewToBack:self.backScreen];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Index Carousel Dots
//Esconde el carousel
- (void)hideCasrousel {

    self.buttonsBar.hidden = YES;
}

//  Muesta el carousel
- (void)unhideCasrousel {

    self.buttonsBar.hidden = NO;
}

- (void)setCarouselBar {

    CGFloat buttonsBarX = center(SCREEN_WIDTH, ((INDEXDOTWIDTH * [self.onboardingUIPageVC.pantallas count]) + (ESPACIADO * ([self.onboardingUIPageVC.pantallas count] - 1))));

    CGFloat buttonsBarY = SCREEN_HEIGHT - INDEXDOTHIGH - 15;
    CGFloat buttonsBarW = INDEXDOTWIDTH;
    CGFloat buttonsBarH = INDEXDOTHIGH;
    self.buttonsBar = [[BSROnboardingCarouselBar alloc] initWithFrame:CGRectMake(buttonsBarX, buttonsBarY, buttonsBarW, buttonsBarH) numberOfPages:[self.onboardingUIPageVC.pantallas count] withEspaciado:ESPACIADO];

    [self.view addSubview:self.buttonsBar];
}

@end
- (void)createOnboarding {

    //  Onboarding Screens
    pag1ViewController *vc1 = [[pag1ViewController alloc] init];
    pag2ViewController *vc2 = [[pag2ViewController alloc] init];
    BSRComodinesSuperClubOnboardingScreen1 *vc3 = [[BSRComodinesSuperClubOnboardingScreen1 alloc] init];

     self.vc = [[BSRGenericOnboarding alloc] initWithArrayOfControllers:[[NSArray alloc] initWithObjects:vc1, vc2, vc3,nil]
                                                                    andCallerController:self];

    self.vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    [self presentViewController:self.vc animated:NO completion:nil];
}