-1

first take a look on this picture from localScope app :

localScope

i have 2 (simple?) questions :

  1. how can i paginate my icons like this?

  2. how can i detect witch icon is " selected "

thank you.

Red Mak
  • 1,176
  • 2
  • 25
  • 56

2 Answers2

1

Answer to the first question: You have to make your scroll view as big as the page size, enable its pagingEnabled property, then somehow make it to display elements and respond to touches outside of its bounds. See this code and these links:

@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);
}

See also Paging UIScrollView in increments smaller than frame size (Split's answer)

Answer to the second question: you can calculate the selected page using this formula:

int selectedIndex = (scrollView.contentOffset + scrollView.size.width / 2) / scrollView.size.width;
Community
  • 1
  • 1
  • thank you i'll try this tomorrow at work and will tell you if i do it and how. – Red Mak Jul 05 '12 at 18:38
  • to be honest, i was not able to make this work and i found "MHPagingScrollView" to do what i need, but i still want to know how this work, so i'm looking to her source code. but in the end i think that Srikar solution is the best approach for me because i have just 3 icons to scroll.ill use a customized tabbar. – Red Mak Jul 11 '12 at 09:54
0

Well one clean & memory efficient approach is to have a UINavigationController & UIToolBar like so -

enter image description here

When the user taps on any button in the UIToolBar invoke that particular viewController by popping and pushing them.

I hope its clear that the look and feel can be achieved close to what you are showing in the image, I am talking about the functionality.

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
  • thank you, in fact you are right, its the 'normal' way to do it in ios but i want to try something new :) – Red Mak Jul 05 '12 at 18:19
  • you can try something new even by using the normal way ;) what i mean is the underlying implementation can be this time tested way (using uitoolbar+naviagation...) but the UI & look-feel you can do innovations. Skys the limit there. – Srikar Appalaraju Jul 05 '12 at 18:20
  • i miss an "L" and i got -1 ok !! – Red Mak Jul 05 '12 at 18:34
  • Srikar, your approach is the best way to do what i need because i have just 3 icons, so i'll use a customized tabbar.thank's – Red Mak Jul 11 '12 at 09:56