So question is: How to manually slide to specific item in TTTabStrip (put 开发者_运维技巧selected to the center or make content offset)
@interface TTT : NSObject {
TTTabStrip* _slider;
}
@implementation TTT
_slider.selectedTabIndex = index;
//This will select item in TTTabStrip view, and if item is out of screen, it wount be shown on _slider view display. What is need is to set content offset to the internal scroll view.
So main strategy is to offset selected item to the center of _slider view.
Other way is take subviews from TTTabStrip and if it is UIScrollView then it is our object.
@interface SomeClass : UIViewController <UIScrollViewDelegate> {
TTTabStrip* _slider;
UIScrollView* _sliderScrollView;
}
@property (nonatomic, retain) IBOutlet TTTabBar* slider;
@end
@implementation SomeClass
@synthesize slider = _slider;
.......
- (void) someMethod {
for (UIView* internalView in self.slider.subviews) {
if ([internalView isKindOfClass:[UIScrollView class]]) {
_sliderScrollView = [internalView retain];
_sliderScrollView.delegate = self;
}
}
}
@end
I added a new function to TTTabStrip. The offset has to be manually entered, but it fits my problem:
@interface TTTabStrip (Private)
- (void)updateOverflow;
@end
@implementation TTTabStrip (SelectOffset)
- (void)selectTabIndex:(NSInteger)tabIndex withOffset:(float)offset {
self.selectedTabIndex = tabIndex;
_scrollView.contentOffset = CGPointMake(offset, 0);
[self updateOverflow];
}
@end
精彩评论