开发者

How to manually slide to specific item in TTTabStrip (put selected to the center or make content offset)

开发者 https://www.devze.com 2023-01-30 08:11 出处:网络
So question is: How to manually slide to specific item in TTTabStrip (put 开发者_运维技巧selected to the center or make content offset)

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号