我相信天气应用程序正在使用UIPageController
,并且过渡效果会自动随之而来。你可以找到很多关于它是如何工作的教程(例如看看这个)。
在应用的视图控制器头文件中,为 : 添加一个属性UIPageViewController
:
#import <UIKit/UIKit.h>
@interface YourAppViewController : UIViewController <UIPageViewControllerDataSource>
@property (strong, nonatomic) UIPageViewController *pageController;
@end
在您应用的视图控制器 .m 文件中,实现以下方法:
增加/减少屏幕索引并返回视图控制器显示):
- (UIViewController *) pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [(YourAppViewController *)viewController index];
if (index == 0) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *) pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = [(YourAppViewController *)viewController index];
index++;
if (index == 5) {
return nil;
}
return [self viewControllerAtIndex:index];
}
最后,设置页面指示器中的点数以及必须在开始时选择哪个点。
- (NSInteger) presentationCountForPageViewController:
(UIPageViewController *)pageViewController
{
// The number of items reflected in the page indicator.
return 5;
}
- (NSInteger) presentationIndexForPageViewController:
(UIPageViewController *)pageViewController
{
// The selected item reflected in the page indicator.
return 0;
}