- Fix autolayout management
This commit is contained in:
parent
7a34b09ccf
commit
f217268512
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
@property (nonatomic, strong) UIButton *itemButton;
|
@property (nonatomic, strong) UIButton *itemButton;
|
||||||
@property (nonatomic) UIDeviceOrientation orientation;
|
@property (nonatomic) UIDeviceOrientation orientation;
|
||||||
|
@property (nonatomic, assign) BOOL didSetupConstraints;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -45,10 +46,12 @@
|
|||||||
- (void) layoutSubviews {
|
- (void) layoutSubviews {
|
||||||
|
|
||||||
//[_itemButton autoPinEdgesToSuperviewMargins];
|
//[_itemButton autoPinEdgesToSuperviewMargins];
|
||||||
|
if (!_didSetupConstraints) {
|
||||||
[_itemButton autoCenterInSuperview];
|
[_itemButton autoCenterInSuperview];
|
||||||
[_itemButton autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self];
|
[_itemButton autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self];
|
||||||
[_itemButton autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
[_itemButton autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
||||||
|
_didSetupConstraints = YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)deviceOrientationDidChange:(NSNotification *)notification {
|
- (void)deviceOrientationDidChange:(NSNotification *)notification {
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
@property (nonatomic) NSUInteger subItemRows;
|
@property (nonatomic) NSUInteger subItemRows;
|
||||||
@property (nonatomic, strong) TabBarPickerSubItemsView *subItemSelector;
|
@property (nonatomic, strong) TabBarPickerSubItemsView *subItemSelector;
|
||||||
@property (nonatomic) BOOL show;
|
@property (nonatomic) BOOL show;
|
||||||
|
@property (nonatomic, assign) BOOL didSetupConstraints;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -89,14 +90,15 @@
|
|||||||
|
|
||||||
- (void) layoutSubviews {
|
- (void) layoutSubviews {
|
||||||
|
|
||||||
if ([self.constraints count] > 0) {
|
/*if ([self.constraints count] > 0) {
|
||||||
|
|
||||||
[NSLayoutConstraint deactivateConstraints:self.constraints];
|
[NSLayoutConstraint deactivateConstraints:self.constraints];
|
||||||
[NSLayoutConstraint deactivateConstraints:_subItemSelector.constraints];
|
[NSLayoutConstraint deactivateConstraints:_subItemSelector.constraints];
|
||||||
for (TabBarItem *item in _tabBarItems) {
|
for (TabBarItem *item in _tabBarItems) {
|
||||||
[item.constraints autoRemoveConstraints];
|
[item.constraints autoRemoveConstraints];
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
if (!_didSetupConstraints) {
|
||||||
|
|
||||||
switch (_position) {
|
switch (_position) {
|
||||||
case TabBarPickerPositionLeft:{
|
case TabBarPickerPositionLeft:{
|
||||||
@ -142,10 +144,7 @@
|
|||||||
break;
|
break;
|
||||||
case TabBarPickerPositionBottom:
|
case TabBarPickerPositionBottom:
|
||||||
default:{
|
default:{
|
||||||
if (!_show) {
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[self autoPinEdgeToSuperviewMargin:ALEdgeBottom];
|
[self autoPinEdgeToSuperviewMargin:ALEdgeBottom];
|
||||||
[self autoSetDimension:ALDimensionHeight toSize:44];
|
[self autoSetDimension:ALDimensionHeight toSize:44];
|
||||||
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:_layoutRelation];
|
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:_layoutRelation];
|
||||||
@ -157,17 +156,16 @@
|
|||||||
|
|
||||||
[_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:_itemSpacing insetSpacing:YES matchedSizes:YES];
|
[_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:_itemSpacing insetSpacing:YES matchedSizes:YES];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self updateConstraintsIfNeeded];
|
|
||||||
|
|
||||||
[_subItemSelector layoutSubviews];
|
[_subItemSelector layoutSubviews];
|
||||||
|
_didSetupConstraints = YES;
|
||||||
|
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
[self updateConstraintsIfNeeded];
|
||||||
[self show];
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setPosition:(TabBarPickerPosition)position {
|
- (void) setPosition:(TabBarPickerPosition)position {
|
||||||
|
|||||||
@ -9,11 +9,15 @@
|
|||||||
#import "TabBarPickerSubItemsView.h"
|
#import "TabBarPickerSubItemsView.h"
|
||||||
#import <PureLayout/PureLayout.h>
|
#import <PureLayout/PureLayout.h>
|
||||||
|
|
||||||
|
#define DEFAULT_ITEM_HEIGHT 44
|
||||||
|
|
||||||
@interface TabBarPickerSubItemsView()
|
@interface TabBarPickerSubItemsView()
|
||||||
|
|
||||||
@property (nonatomic) NSUInteger itemsPerRow;
|
@property (nonatomic) NSUInteger itemsPerRow;
|
||||||
|
@property (nonatomic) CGFloat itemHeight;
|
||||||
@property (nonatomic) NSUInteger rows;
|
@property (nonatomic) NSUInteger rows;
|
||||||
@property (nonatomic, strong) UICollectionView *subItemCollectionView;
|
@property (nonatomic, strong) UICollectionView *subItemCollectionView;
|
||||||
|
@property (nonatomic, assign) BOOL didSetupConstraints;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -25,7 +29,7 @@
|
|||||||
if (self) {
|
if (self) {
|
||||||
_itemsPerRow = itemsPerRow;
|
_itemsPerRow = itemsPerRow;
|
||||||
_itemsArray = [[NSMutableArray alloc] initWithArray:items];
|
_itemsArray = [[NSMutableArray alloc] initWithArray:items];
|
||||||
|
_itemHeight = DEFAULT_ITEM_HEIGHT;
|
||||||
_rows = 0;
|
_rows = 0;
|
||||||
|
|
||||||
for (TabBarItem *item in _itemsArray) {
|
for (TabBarItem *item in _itemsArray) {
|
||||||
@ -33,7 +37,8 @@
|
|||||||
_rows = ceil(([[item subItems] count]/_itemsPerRow));
|
_rows = ceil(([[item subItems] count]/_itemsPerRow));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[self setBackgroundColor:[UIColor whiteColor]];
|
|
||||||
|
[self setBackgroundColor:[UIColor redColor]];
|
||||||
/*_subItemCollectionView = [[UICollectionView alloc] initForAutoLayout];
|
/*_subItemCollectionView = [[UICollectionView alloc] initForAutoLayout];
|
||||||
[_subItemCollectionView setPagingEnabled:YES];
|
[_subItemCollectionView setPagingEnabled:YES];
|
||||||
[_subItemCollectionView setDelegate:self];
|
[_subItemCollectionView setDelegate:self];
|
||||||
@ -50,7 +55,7 @@
|
|||||||
|
|
||||||
- (void) layoutSubviews {
|
- (void) layoutSubviews {
|
||||||
|
|
||||||
if ([self.constraints count] > 0) {
|
/*if ([self.constraints count] > 0) {
|
||||||
|
|
||||||
[NSLayoutConstraint deactivateConstraints:self.constraints];
|
[NSLayoutConstraint deactivateConstraints:self.constraints];
|
||||||
|
|
||||||
@ -59,14 +64,18 @@
|
|||||||
[subItem.constraints autoRemoveConstraints];
|
[subItem.constraints autoRemoveConstraints];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
[self autoConstrainAttribute:ALEdgeTop toAttribute:ALMarginTop ofView:self.superview withOffset:self.superview.frame.size.height];
|
if (!_didSetupConstraints) {
|
||||||
|
|
||||||
|
[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:-(_rows*_itemHeight)];
|
||||||
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual];
|
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual];
|
||||||
[self autoSetDimension:ALDimensionHeight toSize:_rows*44];
|
[self autoSetDimension:ALDimensionHeight toSize:_rows*_itemHeight];
|
||||||
|
|
||||||
[_subItemCollectionView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
[_subItemCollectionView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
||||||
[_subItemCollectionView autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self];
|
[_subItemCollectionView autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self];
|
||||||
[_subItemCollectionView setBackgroundColor:[UIColor redColor]];
|
[_subItemCollectionView setBackgroundColor:[UIColor redColor]];
|
||||||
|
_didSetupConstraints = YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
@interface TabBarSubItem()
|
@interface TabBarSubItem()
|
||||||
|
|
||||||
@property (nonatomic) UIDeviceOrientation orientation;
|
@property (nonatomic) UIDeviceOrientation orientation;
|
||||||
|
@property (nonatomic, assign) BOOL didSetupConstraints;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -52,10 +53,16 @@
|
|||||||
|
|
||||||
- (void) layoutSubviews {
|
- (void) layoutSubviews {
|
||||||
|
|
||||||
if ([self.constraints count] > 0) {
|
/*if ([self.constraints count] > 0) {
|
||||||
|
|
||||||
[NSLayoutConstraint deactivateConstraints:self.constraints];
|
[NSLayoutConstraint deactivateConstraints:self.constraints];
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (_didSetupConstraints) {
|
||||||
|
|
||||||
|
|
||||||
|
_didSetupConstraints = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user