使用块轻松实现分页滚动视图。
- (NSInteger)currentPage- (NSInteger)nextPage- (NSInteger)lastPage- (NSInteger)numberOfPages- (void)addPageWithHandler:(void (^)(UIView * pageView))handlerhandler 是一个传递包含新页面子视图的视图的块,因此在那个块中,您只需将要在该页面上显示的所有视图添加到 pageView。它会正常工作。对子视图应用自动布局不是必需的,但推荐使用。
无论如何,如果您决定使用自动布局,我建议使用一个名为 Masonry 的框架。非常棒的东西。
这里是一个没有使用自动布局的示例,以简化事情。如果您想查看使用自动布局实现的示例,请查看演示应用
[paginatedScrollView addPageWithHandler:^(UIView * pageView) {
UIView * square = [UIView new];
[square setBackgroundColor:[UIColor redColor]];
[square setFrame:CGRectMake(0, 0, 100, 100)];
[pageView addSubview:square];
}];- (void)jumpToPage:(NSInteger)page bounce:(CGFloat)bounce completion:(void (^)(void))completionpage 指定要跳转到的页面的索引。bounce 指定跳转将执行的弹跳效果量。推荐值为 0-40,其中 0 是没有弹跳。completion 是在跳转完成后要执行的块。这里有一些示例
// Jumping to the 4th page with no bounce effect and completion
[paginatedScrollView jumpToPage:3 bounce:0 completion:^{
NSLog(@"Jump finished!");
}];
// Jumping to the first page with a normal bounce effect and no completion
[paginatedScrollView jumpToPage:0 bounce:20 completion:nil];
// Jumping to the next page with a little bounce effect and no completion
[paginatedScrollView jumpToPage:[paginatedScrollView nextPage] bounce:10 completion:nil];
// Jumping to the last page with a high bounce effect and no completion
[paginatedScrollView jumpToPage:[paginatedScrollView lastPage] bounce:40 completion:nil];BOOL isJumpingNSTimeInterval jumpDurationPerPage0.10.05-0.175void (^actionWhenTappedBlock)(DRPaginatedScrollView *)默认值
^(DRPaginatedScrollView * paginatedScrollView) {
[paginatedScrollView jumpToPage:[paginatedScrollView nextPage] bounce:0 completion:nil];
}paginatedScrollView configurePageIndicatorWithHandler:)。pageView clipSubview:untilPage:)和永久截取(pageView clipSubviewForever:)。目前没有贡献者。
你可以随意使用它。我只希望能够知道你是否在某个自己的项目中使用它。