IOS - great segmented management like the App Store app

I create an application and in one of the types of navigation, I have a very similar design, such as the App Store application - see details | Reviews | Linked section. Following similar lines, I want to implement segmented control in the same way that Apple did in my application. (This is also similar to what Apple does in Artist → Albums view mode in the iOS 7 music app by default, albeit for the table title (maybe).)

  • If you scroll up when the segmented control container touches the navigation bar, it stays there.
  • It also allows the user to notice that this is a kind of overlay due to the alpha associated with it.
  • When you scroll down, it moves to the right place if necessary.

What I've done -

I created a container view with a segmented control. When the scrollView scrolls, I rearrange the container view to perform a sticky effect. This is just pseudo code, but my code really works.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == self.labTestScrollView)
    {
        /*
         As soon as the user scrolls up, y changes, therefore, we need to stick the options container view
         such that it doesn't go past the UINavigationBar
         Need to check if the origin of the options container view in the coordinate system of the main
         superview is just gone past the UINavigationBar in this controller view.
         - get the bounds rect for the options container view
         - convert these bounds and position them in the coordinates of this controller view
         - check if origin.x for container view is less than that of view.origin.y
         - if less than stick it by converting the headerFrame to the coordinate system of the options 
         container view; and raise the stuck flag
         - if greater, check if the stuck flag is raised; check for another object in space before the container view and adjust accordingly.
         */
    }
}

There are two problems:

  • No overlay effect. I can tweak the alpha to make the effect a little more noticeable, but that doesn't seem natural.
  • The second problem is related to the first. This seems like a very specific solution. I look forward to what is more natural; and something that might work by default using table views or something like that.
+4
source share
2 answers

UITableView?

" " 0 . 1 UISegmentedControl.

. , "", Apple; GPUimage ?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return section == 0 ? 1 : 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *identifier = indexPath.section == 0 ? @"header" : @"content";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // customize cell
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if(section == 1) {
        UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Foo", @"Bar"]];
        segmentedControl.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.95];
        return segmentedControl;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return section == 0 ? 0 : 44;
}

;)

+10

2 .

- UITableView.

, ..

, .

, scrollView: didScroll...

, scrollView , . .

. , , - .

+4

All Articles