Skip to content

Commit

Permalink
new layout style:VTLayoutStyleCenter
Browse files Browse the repository at this point in the history
  • Loading branch information
tianzhuo112 committed Jun 1, 2016
1 parent c227062 commit c0bd7cc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
22 changes: 12 additions & 10 deletions VTMagic/VTEnumType.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
#ifndef VTEnumType_h
#define VTEnumType_h

/** 导航栏布局样式 */
typedef NS_ENUM(NSUInteger, VTLayoutStyle) {
/** 默认样式,item自适应文本宽度,间距由itemSpacing决定 */
VTLayoutStyleDefault,
/** items等分导航条宽度,常用于item数较少时 */
VTLayoutStyleDivide,
/** 导航栏居中布局,间距由itemSpacing决定 */
VTLayoutStyleCenter,
/** 自定义item宽度(itemWidth) */
VTLayoutStyleCustom,
};

/** 页面滑动切换样式 */
typedef NS_ENUM(NSUInteger, VTSwitchStyle) {
/** 默认样式,切换时有颜色渐变效果 */
Expand All @@ -31,16 +43,6 @@ typedef NS_ENUM(NSUInteger, VTSwitchEvent) {
VTSwitchEventUnkown,
};

/** 导航条布局样式 */
typedef NS_ENUM(NSUInteger, VTLayoutStyle) {
/** 默认样式,item自适应文本宽度,间距由itemSpacing决定 */
VTLayoutStyleDefault,
/** items等分导航条宽度,常用于item数较少时 */
VTLayoutStyleDivide,
/** 自定义item宽度(itemWidth) */
VTLayoutStyleCustom,
};

/** UIPanGestureRecognizer手势方向 */
typedef NS_ENUM(NSUInteger, VTPanRecognizerDirection) {
VTPanRecognizerDirectionUndefined, // 初始
Expand Down
2 changes: 1 addition & 1 deletion VTMagic/VTMagicView.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
* 两个导航菜单item文本之间的间距,默认是25
* 如果分类item包含图片,则实际间距可能会更小
*
* @warning 该属性仅VTLayoutStyleDefault样式下有效
* @warning 该属性仅VTLayoutStyleDefault和VTLayoutStyleCenter样式下有效
*/
@property (nonatomic, assign) CGFloat itemSpacing;

Expand Down
1 change: 1 addition & 0 deletions VTMagic/VTMagicView.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ - (void)updateFrameForSubviews
_menuBar.frame = CGRectMake(leftItemWidth, topY, catWidth, _navigationHeight);
if (!CGRectEqualToRect(_menuBar.frame, originalCatFrame)) {
[_menuBar resetItemFrames];
[self updateMenuBarState];
}

CGRect sliderFrame = _sliderView.frame;
Expand Down
25 changes: 23 additions & 2 deletions VTMagic/VTMenuBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ - (void)resetItemFrames

switch (_layoutStyle) {
case VTLayoutStyleDivide:
[self resetFramesForAutoDivide];
[self resetFramesForDivide];
break;
case VTLayoutStyleCenter:
[self resetFramesForCenter];
break;
case VTLayoutStyleCustom:
[self resetFramesForCustom];
Expand Down Expand Up @@ -173,7 +176,7 @@ - (void)resetFramesForDefault
}
}

- (void)resetFramesForAutoDivide
- (void)resetFramesForDivide
{
CGRect frame = CGRectZero;
NSInteger count = _menuTitles.count;
Expand All @@ -189,6 +192,24 @@ - (void)resetFramesForAutoDivide
}
}

- (void)resetFramesForCenter
{
[self resetFramesForDefault];
CGFloat menuWidth = CGRectGetWidth(self.frame);
CGRect lastFame = [[_frameList lastObject] CGRectValue];
CGFloat contentWidth = menuWidth - _menuInset.right;
CGFloat itemOffset = (contentWidth - CGRectGetMaxX(lastFame))/2;
if (itemOffset <= 0) return;
CGRect frame = CGRectZero;
NSArray *frames = [NSArray arrayWithArray:_frameList];
[_frameList removeAllObjects];
for (NSValue *value in frames) {
frame = [value CGRectValue];
frame.origin.x += itemOffset;
[_frameList addObject:[NSValue valueWithCGRect:frame]];
}
}

- (void)resetFramesForCustom
{
CGRect frame = CGRectZero;
Expand Down

0 comments on commit c0bd7cc

Please sign in to comment.