【发布时间】:2012-07-05 17:27:29
【问题描述】:
首先看一下来自 localScope 应用程序的这张图片:
我有 2 个(简单?)问题:
我怎样才能像这样对我的图标进行分页?
如何检测女巫图标被“选中”
谢谢。
【问题讨论】:
-
什么是“Uiscrollview”?请在您的问题上多加努力。
-
我想念一个“L”,它不是世界的和!
标签: ios uiscrollview pagination
首先看一下来自 localScope 应用程序的这张图片:
我有 2 个(简单?)问题:
我怎样才能像这样对我的图标进行分页?
如何检测女巫图标被“选中”
谢谢。
【问题讨论】:
标签: ios uiscrollview pagination
回答第一个问题:您必须使滚动视图与页面大小一样大,启用其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;
【讨论】:
嗯,一种干净且内存高效的方法是像这样使用UINavigationController 和UIToolBar -
当用户点击UIToolBar 中的任何按钮时,通过弹出并按下它们来调用特定的viewController。
我希望可以清楚地看到外观和感觉可以接近您在图像中显示的内容,我说的是功能。
【讨论】: