ios - UIPageViewController 在我的 UIImage 的底部创建一个边框以及如何摆脱它

标签 ios iphone uiimage nsarray uipageviewcontroller

我对 UIPageViewControllers 比较陌生,刚刚为我的应用程序的“演练”实现了它。

问题是,我显示的每张图片在底部和侧面都有一个边框,带有 pageViewIndicators,因此,图片没有全屏显示,看起来是捆绑在一起的。

我在这里附上一些图片以供引用:

enter image description here

enter image description here

我只是想去掉这个边框,让 pageIndicators 在背景中覆盖全屏图像。此外,当滑动到下一个屏幕时,我不希望图像之间出现黑色边框(根据第二个屏幕截图)。

这是一些代码。我有一个 WalkthroughViewController 文件,其中包含对正在创建的图像的引用:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self.view setBackgroundColor:[UIColor clearColor]];
    CGRect insetFrame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    _imageView = [[UIImageView alloc] initWithFrame:insetFrame];
    _imageView.backgroundColor = [UIColor clearColor];
    [_imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
    [_imageView setImage:[UIImage imageNamed:_model.imageName]];
    [[self view] addSubview:_imageView];
}

在我的 PageViewController 的 viewDidLoad 中,我有:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [[self view] setBackgroundColor:[UIColor blackColor]];

    _modelArray = [NSMutableArray arrayWithObjects:[[ImageModel alloc] initWithImageName:@"TimelineTut.png"],
                  [[ImageModel alloc] initWithImageName:@"Tut 1.png"],
                [[ImageModel alloc] initWithImageName:@"Tut 2.png"],
                   [[ImageModel alloc] initWithImageName:@"newtut3.png"],
                   [[ImageModel alloc] initWithImageName:@"tut 4.png"],
                   nil];

    _pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
                                                          navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                                                                        options:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:50.0f] forKey:UIPageViewControllerOptionInterPageSpacingKey]];
    
    _pageViewController.delegate = self;
    _pageViewController.dataSource = self;
    
    WalkthroughViewController *imageViewController = [[WalkthroughViewController alloc] init];
    imageViewController.model = [_modelArray objectAtIndex:0];
    NSArray *viewControllers = [NSArray arrayWithObject:imageViewController];
    
    [self.pageViewController setViewControllers:viewControllers
                                      direction:UIPageViewControllerNavigationDirectionForward
                                       animated:NO
                                     completion:nil];
    
    [self addChildViewController:_pageViewController];
    [self.view addSubview:_pageViewController.view];
    
    [_pageViewController didMoveToParentViewController:self];
    

    //CGRect pageViewRect = self.view.bounds;
    
   // pageViewRect = CGRectInset(pageViewRect, 0.0, 0.0);
    //self.pageViewController.view.frame = pageViewRect;

}

上面的最后三行被注释掉了,但如果我取消注释并保留值,它会保持不变。但是,如果我将 0.0 更改为 40.0 之类的值,它就会看起来拉长了,这是可以理解的。

我已经尝试在 中将 ImageRatio 设置为 AspectFillFitScaleToFill 等WalkthroughViewController 但这并没有消除边框。

View Controller 完全是在代码中创建的,而不是在 Storyboard 中创建的,它几乎看起来像这个问题(Putting a bar on the bottom of the UIPageViewController),但我不想要边框,我不认为我正在嵌入容器中?

更新:

通过更改这行代码中的值:

_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
                                                      navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                                                                    options:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:50.0f] forKey:UIPageViewControllerOptionInterPageSpacingKey]];

从 50 到 0,我去掉了图像边上的空间。但是底部的边距仍然存在。

如何去除黑色边框,同时将 pageViewIndicators 保持为图像的叠加层,从而使图像全屏显示,而不是因为边框而被压扁?

任何关于这方面的指导将不胜感激。

最佳答案

我设法通过在此处选择此问题的答案来克服此实现 How to remove the bottom gap of UIPageViewController

基本前提是确保我将 PageViewController 的 View 扩展 15,这会将页面指示器移至底部。幸运的是我的背景是黑色的(问题中上面的紫色图像仅供引用)并且图像看起来没有被压扁。虽然这不是一个理想的解决方案,但它现在可以完成工作。

关于ios - UIPageViewController 在我的 UIImage 的底部创建一个边框以及如何摆脱它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22658671/

相关文章:

ios - 如何在iOS中将NSString数据转换为Uiimage View

ios - 为什么 CGBitmapContextCreateImage 比 [UIImage initWithData :]? 慢

iOS UITableView 滚动到部分底部

ios - 如何快速写入和读取 float 据,而不是使用字符串?

ios - 获取嵌入到 CollectionView 中的 TableView 中的 IndexPath 项

iphone - 在给定 cell.imageView 的情况下发现 UITableViewCell

iphone - 自动构建 iPhone 应用程序需要哪些步骤?

ios - UITableViewController 的圆角

swift - 如何将属性从 cellForRowAtIndexPath 传递到 UIImage View 的子类

iphone - 适用于运行 iOS 的 Cocoa iPhone 和 iPad 的 WebDAV 服务器