简体   繁体   English

如何在PageViewController中将CGGradients融合在一起?

[英]How to blend CGGradients together in PageViewController?

I have a UIPageViewController with 4 pages, by taking the sample from here: http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/ and removing the set images and adding in custom gradients for each view. 我有一个包含4页的UIPageViewController,方法是从此处获取示例: http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/ : http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/并删除设置的图像并为每个视图添加自定义渐变。 Let's say that page 1 is red/yellow, page 2 is yellow/blue, etc, so what I want is when the transition happens between page 1 and 2, instead of seeing a solid line between the two gradient views, as such: 假设第1页是红色/黄色,第2页是黄色/蓝色,等等,所以我想要的是在第1页和第2页之间发生过渡时,而不是看到两个渐变视图之间的实线,例如:

不良行为截图

I'd like to be able to blend the transition and make it look nice. 我希望能够混合过渡并使其看起来不错。 I have found the delegate methods for the PageViewController as likely the place that I need to execute this custom behavior: 我发现PageViewController的委托方法很可能是执行此自定义行为所需的位置:

- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers {
}

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed {
}

From these methods, how could I basically remove the separator line and blend over it with my own custom colors? 从这些方法中,我基本上如何删除分隔线并用我自己的自定义颜色混合? Would I be creating another UIView on top of the existing set of views and animate that? 我是否要在现有视图集之上创建另一个UIView并对其进行动画处理?

The problem is that with a UIPageViewController you are not in charge of the views and (even more important) you don't get to customize the transition animation, so you can't add anything at the join. 问题在于,使用UIPageViewController时,您不负责视图,并且(更重要的是)您无法自定义过渡动画,因此您无法在连接处添加任何内容。

Since you only have four views, I would suggest you abandon UIPageViewController entirely and use instead a paging UIScrollView. 由于您只有四个视图,因此建议您完全放弃UIPageViewController,而改用分页UIScrollView。 This gives you the same behavior - the user can scroll from "page" to "page" - but now you are in complete control of everything inside the UIScrollView's content and can modify / overlay as you see fit. 这给了您相同的行为-用户可以从“页面”滚动到“页面”-但是现在您可以完全控制UIScrollView内容内的所有内容,并且可以根据需要修改/覆盖。 Use the delegate methods to learn when the user is scrolling and when the user has finished. 使用委托方法可以了解用户何时滚动以及用户何时完成滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM