UIScrollView costum分页大小

时间:2012-07-05 17:27:30

标签: ios uiscrollview pagination

首先从localScope应用程序看一下这张照片:

localScope

我有2个(简单?)问题:

  1. 我怎样才能像这样对我的图标进行分页?

  2. 我怎样才能发现女巫图标是"选择"

  3. 谢谢。

2 个答案:

答案 0 :(得分:1)

回答第一个问题:您必须使滚动视图与页面大小一样大,启用其pagingEnabled属性,然后以某种方式使其显示元素并响应触摸超出界限。请参阅此代码和以下链接:

@interface SmallPagedScrollView: UIScrollView <UIScrollViewDelegate> {
    UIEdgeInsets responseInsets;
    NSMutableArray *items;
}

@implementation SmallPagedScrollView

@synthesize responseInsets;

- (id)init
{
if ((self = [super initWithFrame:CGRectMake(x, y, w, h)]))
{
    self.backgroundColor = [UIColor clearColor];
    self.pagingEnabled = YES;
    self.showsHorizontalScrollIndicator = NO;
    self.showsVerticalScrollIndicator = NO;
    self.clipsToBounds = NO;

    CGFloat hInset = 3 * self.width / 2;
    self.responseInsets = UIEdgeInsetsMake(0.0f, hInset, 0.0f, hInset);
    self.delegate = self;

    items = [[NSMutableArray alloc] init];
}
return self;
}

- (void)dealloc
{
[items release];
[super dealloc];
}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
CGPoint parentLocation = [self convertPoint:point toView:self.superview];
CGRect responseRect = self.frame;
responseRect.origin.x -= self.responseInsets.left;
responseRect.origin.y -= self.responseInsets.top;
responseRect.size.width += self.responseInsets.left + self.responseInsets.right;
responseRect.size.height += self.responseInsets.top + self.responseInsets.bottom;

return CGRectContainsPoint(responseRect, parentLocation);
}

另见Paging UIScrollView in increments smaller than frame size(斯普利特的回答)

回答第二个问题:您可以使用以下公式计算所选页面:

int selectedIndex = (scrollView.contentOffset + scrollView.size.width / 2) / scrollView.size.width;

答案 1 :(得分:0)

一个干净的&amp;记忆效率高的方法是拥有UINavigationController&amp; UIToolBar喜欢这样 -

enter image description here

当用户点击UIToolBar中的任何按钮时,通过弹出并推送它来调用特定viewController

我希望它的外观和感觉能够接近您在图像中显示的内容,我正在谈论功能。