iphone - UIScrollView中如何实现水平分页而不垂直分页

标签 iphone uiscrollview paging

我现在正在制作数字漫画。 我的应用程序在不缩放时具有水平分页。 但是当缩放时,图片的高度超过了屏幕的高度。 所以应用程序具有垂直分页。

但我不需要垂直分页。 我想在缩放期间进行水平分页而不进行垂直分页。

请教我。

最佳答案

这真的很简单。正如您的 friend 所建议的,您至少需要两个 UIScrollView。您将需要一个 UIScrollView 用于水平(即分页),并且您将需要一个 UIScrollView 用于每个页面。关键点是(让我们将它们命名为 scrollHorizo​​ntalscrollVertical):

  • scrollHorizo​​ntal.frame.height 必须等于 scrollHorizo​​ntal.contentSize.height(否则,您最终将得到垂直分页)
  • scrollVertical:首先,每个页面都会有一个。框架宽度和 contentSize.width 应匹配且有意义。页面的宽度(在 scrollHorizo​​ntal 中)。当然,您应该让框架高度不超过 scrollHorizo​​ntal.contentSize.height

示例代码:


UIScrollView scrollHorizontal = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

scrollHorizontal.pagingEnabled = YES;
scrollHorizontal.directionalLockEnabled = YES; // not needed but helpful

// Now let's create each page

UIScrollView *scrollPage1 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

[scrollPage1 addSubview:theContentViewForPage1];

scrollPage1.contentSize = CGSizeMake(self.view.bounds.size.width, theContentViewForPage1.bounds.size.height);

// Add page to scrollHorizontal

[scrollHorizontal addSubview:scrollPage1];
[scrollPage1 release];

//...add more pages (REMEMBER to set the scroll view's frame.origin.x accordingly for each additional page)

// Set the scrollHoriztonal content size
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width*NUMBER_OF_PAGES, self.view.bounds.size.height);

// Now add the scrollview to self.view; or even self.view = scrollHorizontal, etc.

关于iphone - UIScrollView中如何实现水平分页而不垂直分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3015709/

相关文章:

iphone - 带有UITableView的UIViewController崩溃

swift - 如何在 swift 中使用 NSLayoutConstraint 根据屏幕尺寸更改设计

objective-c - 带有图像的 UIScrollView

linux - 没有任何交换分区的虚拟内存

mysql - ASP/SQL/Paging - 获取当前页码

php - 在 PHP 中推送通知

iphone - 为 iPhone 创建闹钟应用程序

ios - 按下键盘 Swift iOS 后,我的 Scrollview 不会一直向上滚动

ios - Objective-C 中 UIScrollView 内具有动态高度的 UIWebView

linux - 在 MIPS TLB 中,除了 ASID 字段之外,两个条目是否可能相同?