【问题标题】:UIScrollView costum pagination sizeUIScrollView 服装分页大小
【发布时间】:2012-07-05 17:27:29
【问题描述】:

首先看一下来自 localScope 应用程序的这张图片:

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

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

  2. 如何检测女巫图标被“选中”

谢谢。

【问题讨论】:

  • 什么是“Uiscrollview”?请在您的问题上多加努力。
  • 我想念一个“L”,它不是世界的和!

标签: ios uiscrollview pagination


【解决方案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;

【讨论】:

  • 谢谢你,我明天在工作中试试这个,我会告诉你我是否这样做以及如何做。
  • 说实话,我无法完成这项工作,我发现“MHPagingScrollView”可以满足我的需要,但我仍然想知道它是如何工作的,所以我正在寻找她的来源代码。但最后我认为 Srikar 解决方案对我来说是最好的方法,因为我只有 3 个图标可以滚动。我会使用自定义标签栏。
【解决方案2】:

嗯,一种干净且内存高效的方法是像这样使用UINavigationControllerUIToolBar -

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

我希望可以清楚地看到外观和感觉可以接近您在图像中显示的内容,我说的是功能。

【讨论】:

  • 谢谢你,事实上你是对的,这是在 ios 中的“正常”方式,但我想尝试一些新的 :)
  • 你甚至可以使用正常的方式尝试新的东西;)我的意思是底层实现可以是这次测试的方式(使用 uitoolbar+naviagation...)但是 UI 和外观你可以做创新。在那里突破极限。
  • 我错过了一个“L”,我得到了-1 ok!!
  • Srikar,您的方法是满足我需要的最佳方式,因为我只有 3 个图标,所以我将使用自定义的 tabbar.thank's
猜你喜欢
  • 2011-10-12
  • 2014-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多