-
Notifications
You must be signed in to change notification settings - Fork 831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigation Controller Problem #62
Comments
Hi Mohammad, could you please give me more info about how to reproduce this or add some code? |
The easiest way to reproduce this is to comment out all the segmented controllers in the Demo except segmentedControl4 and embed a navigation controller in the App delegate
If u uncomment the creation of segmented controller 3, everything will work fine, i am keeping the code and hiding the segmented controller 3 that i dont need, but i think there should be a more logical solution, i've been trying for 2 days. maybe you can point out the problem Thanks |
I have the same problem, how can I do?Thanks!@masabusharif @HeshamMegid |
ihenk Can you provide some code in order to help you out? |
_segmentedControl = [[HMSegmentedControl alloc] init];
_segmentedControl.frame = CGRectMake(0, 0, self.width, NAVIGATION_BAR_HEIGHT);
_segmentedControl.font = FONT_15;
_segmentedControl.selectedFont = FONT_BOLD_15;
_segmentedControl.backgroundColor = [UIColor clearColor];
_segmentedControl.backgroundImage = [IMG(IC_SEGMENTED_N) resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];
_segmentedControl.selectionIndicatorColor = SEGMENT_BLUE_COLOR;
_segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
_segmentedControl.selectionIndicatorHeight = 2;
_segmentedControl.selectedTextColor = SEGMENT_BLUE_COLOR;
_segmentedControl.textColor = [UIColor darkGrayColor];
_segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
_segmentedControl.segmentWidthStyle = HMSegmentedControlSegmentWidthStyleDynamic;
NSMutableArray *sectionTitles = [NSMutableArray array];
for (int i = 0; i < _tableViews.count; i++) {
HKAbstractTableView *tableView = _tableViews[i];
tableView.pageIndex = i;
[sectionTitles addObject:[tableView pageTitle]];
tableView.frame = CGRectMake(i * _scrollView.frame.size.width, 0, _scrollView.frame.size.width, _scrollView.frame.size.height);
[_scrollView addSubview:tableView];
}
[_segmentedControl setSectionTitles:sectionTitles];
_segmentedControl.selectedSegmentIndex = self.currentPageIndex;
[_segmentedControl addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
[self addSubview:_segmentedControl];
[self addSubview:_scrollView]; |
CampusNewsController *controller = [[CampusNewsController alloc] init];
self.window.rootViewController = controller;
[self.window makeKeyAndVisible]; Everything is working perfectly UINavigationController *rooterViewController = [[UINavigationController alloc] initWithRootViewController:controller];
self.window.rootViewController = rooterViewController;
[self.window makeKeyAndVisible]; It does not work |
notes:My English is not good, if the English grammar wrong, please forgive me. I found the cause of the problem, because the scrollView (defined in HMSegmentedControl) of contentOffset changed.I found the cause of the problem, because the scrollView (defined in HMSegmentedControl) of contentOffset(y changed) changed. Now, I'm using KVO listening scrollView of contentOffset, when it changes, I reset contentOffset (self.scrollView.contentOffset.x,0). I modified the HMSegmentedControl.m file. [self.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:NULL]; step two: - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if ([keyPath isEqualToString:@"contentOffset"]) {
if (self.scrollView.contentOffset.y != 0) {
self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, 0);
}
}
} Now everything works perfectly, but I do not know why scrollView of contentOffset(y change) will change. |
This happens because of the view controller automatically adjusting the content insets of the scroll view. There are 2 ways around this:
I'll commit the fix but I won't do a Cocoapods release. So you could either point your pod to the head of master (recommended) or do the fix manually. |
I am using the segmented control with images and a scroll view (segmented control 4 in the demo) and everything is working perfectly except when i use a navigation controller, the area of the segmented control seem to have bigger content are and i can scroll vertically and move around the segmented control items
The text was updated successfully, but these errors were encountered: