Merge pull request #3 from giuseppenucifora/sviluppo

Sviluppo
This commit is contained in:
Giuseppe Nucifora 2015-10-29 01:06:18 +01:00
commit 01b55ac158
9 changed files with 208 additions and 33 deletions

View File

@ -4,6 +4,7 @@ use_frameworks!
inhibit_all_warnings!
pod 'PureLayout'
pod 'pop', '~> 1.0'
pod 'UIView-Overlay'
pod 'UIActionSheet-Blocks'
pod 'UIAlertViewBlockExtension'

View File

@ -32,7 +32,7 @@
TabBarSubItem *subItem6 = [TabBarSubItem tabBarSubItemWithName:@"Peppe5" andValue:@"Peppe5"];
TabBarSubItem *subItem7 = [TabBarSubItem tabBarSubItemWithName:@"Peppe6" andValue:@"Peppe6"];
TabBarPickerSubItemsView *locationSubview = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:YES];
TabBarPickerSubItemsView *locationSubview = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeDistance subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:YES];
TabBarItem *location = [[TabBarItem alloc] initWithSubItemView:locationSubview];
[location setItemName:@"Location"];
@ -40,7 +40,7 @@
[location setSelectedImage:[UIImage imageNamed:@"location_selected"]];
[location setHighlightedImage:[UIImage imageNamed:@"location_highlighted"]];
TabBarPickerSubItemsView *locationSubview1 = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:NO];
TabBarPickerSubItemsView *locationSubview1 = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeDateAndTime subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:NO];
TabBarItem *location1 = [[TabBarItem alloc] initWithSubItemView:locationSubview1];
[location1 setItemName:@"Location2"];
@ -48,7 +48,7 @@
[location1 setSelectedImage:[UIImage imageNamed:@"location_selected"]];
[location1 setHighlightedImage:[UIImage imageNamed:@"location_highlighted"]];
TabBarPickerSubItemsView *locationSubview2 = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:NO];
TabBarPickerSubItemsView *locationSubview2 = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeCheckBox subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:NO];
TabBarItem *location2 = [[TabBarItem alloc] initWithSubItemView:locationSubview2];
[location2 setItemName:@"Location3"];
@ -56,7 +56,7 @@
[location2 setSelectedImage:[UIImage imageNamed:@"location_selected"]];
[location2 setHighlightedImage:[UIImage imageNamed:@"location_highlighted"]];
TabBarPickerSubItemsView *locationSubview3 = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:NO];
TabBarPickerSubItemsView *locationSubview3 = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypePrice subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:NO];
TabBarItem *location3 = [[TabBarItem alloc] initWithSubItemView:locationSubview3];
[location3 setItemName:@"Location4"];
@ -64,7 +64,7 @@
[location3 setSelectedImage:[UIImage imageNamed:@"location_selected"]];
[location3 setHighlightedImage:[UIImage imageNamed:@"location_highlighted"]];
TabBarPickerSubItemsView *locationSubview4 = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:NO];
TabBarPickerSubItemsView *locationSubview4 = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButton subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:NO];
TabBarItem *location4 = [[TabBarItem alloc] initWithSubItemView:locationSubview4];
[location4 setItemName:@"Location5"];

View File

@ -94,6 +94,10 @@
[_itemButton setHighlighted:highlighted];
}
- (void) setItemName:(NSString *)itemName {
[_itemSubView setItemName:itemName];
}
- (void) itemButtonTapped {
if (_delegate && [_delegate respondsToSelector:@selector(tabBarItemSelected:)]) {
[_delegate tabBarItemSelected:self];

View File

@ -12,6 +12,7 @@
#import "MMCPSScrollView.h"
#import <UIView-Overlay/UIView+Overlay.h>
#import "NSString+HexColor.h"
#import <QuartzCore/QuartzCore.h>
@interface TabBarPicker() <TabBarPickerSubItemsViewDelegate,TabBarItemDelegate>
@ -25,6 +26,7 @@
@property (nonatomic, strong) NSMutableArray *tabBarItemsConstraints;
@property (nonatomic, strong) TabBarItem *selectedTabBarItem;
@property (nonatomic, strong) UIView *separator;
@property (nonatomic, strong) UIView *tabBarView;
@property (nonatomic, strong) MMCPSScrollView *subItemScrollView;
@ -72,7 +74,11 @@
_tabBarView = [[UIView alloc] initForAutoLayout];
[self addSubview:_tabBarView];
_separator = [[UIView alloc] initForAutoLayout];
[_separator.layer setMasksToBounds:NO];
[_separator setBackgroundColor:[[UIColor lightGrayColor] colorWithAlphaComponent:0.3]];
for (NSObject *item in items) {
if (item && [item isKindOfClass:[TabBarItem class]]) {
@ -93,6 +99,10 @@
[_subItemScrollView setPageSize:1];
[self addSubview:_subItemScrollView];
[self addSubview:_tabBarView];
[self addSubview:_separator];
}
[self updateConstraintsIfNeeded];
@ -160,6 +170,10 @@
[_tabBarView autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_tabBarView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self];
[_separator autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview];
[_separator autoSetDimension:ALDimensionHeight toSize:1];
[_separator autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_tabBarView];
[_tabBarItems autoSetViewsDimension:ALDimensionHeight toSize:44.0];
[[_tabBarItems firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
@ -365,6 +379,12 @@
}
#pragma mark -
#pragma mark TabBarPickerSubItemsViewDataSource
#pragma mark -
#pragma mark TabBarItemDelegate
@ -394,11 +414,32 @@
#pragma mark MMCPSScrollViewDelegate
- (void)scrollView:(MMCPSScrollView *)scrollView didScrollToPage:(NSUInteger)pageIndex {
NSLog(@"The MMCPSScrollView is now on page %i.", pageIndex);
if ([scrollView currentPage] > 0 && [scrollView currentPage] <= [_tabBarItems count]) {
TabBarItem *selectedItem = [_tabBarItems objectAtIndex:[scrollView currentPage]-1];
for (TabBarItem *item in _tabBarItems) {
if (![item isEqual:selectedItem]) {
[item setHighlighted:NO];
}
else {
[item setHighlighted:YES];
}
}
if (!_isShow) {
[self show];
}
else {
if(![_selectedTabBarItem isEqual:selectedItem]) {
}
}
_selectedTabBarItem = selectedItem;
}
}
- (void)scrollView:(MMCPSScrollView *)scrollView willScrollToPage:(NSUInteger)pageIndex {
NSLog(@"The MMCPSScrollView is now going to page %i.", pageIndex);
}
#pragma mark -

View File

@ -14,10 +14,11 @@
typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
// Informational
TabBarPickerSubItemsViewTypeData,
TabBarPickerSubItemsViewTypeString,
TabBarPickerSubItemsViewTypeButtons,
TabBarPickerSubItemsViewTypeCheckBox
TabBarPickerSubItemsViewTypeDistance,
TabBarPickerSubItemsViewTypeDateAndTime,
TabBarPickerSubItemsViewTypePrice,
TabBarPickerSubItemsViewTypeCheckBox,
TabBarPickerSubItemsViewTypeButton,
};
@protocol TabBarPickerSubItemsViewDelegate <NSObject>
@ -51,4 +52,5 @@ typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems needsLocalization:(BOOL) needsLocalization;
- (void) setItemName:(NSString *) itemName;
@end

View File

@ -13,7 +13,7 @@
#import "SharedLocationManager.h"
#import "UIAlertView+BlockExtension.h"
@interface TabBarPickerSubItemsView()
@interface TabBarPickerSubItemsView() <UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic, assign) BOOL didSetupConstraints;
@property (nonatomic) TabBarPickerSubItemsViewType type;
@ -23,6 +23,11 @@
@property (nonatomic, strong) UILabel *switchBarLabel;
@property (nonatomic, strong) UIButton *localizationButton;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) UIView *HUD;
@property (nonatomic, strong) UIPickerView *pickerView;
@end
@ -38,6 +43,15 @@
if (self) {
[self setUserInteractionEnabled:YES];
_subItems = [[NSMutableArray alloc] init];
for (NSObject *subItem in subItems) {
if ([subItem isKindOfClass:[TabBarSubItem class]]) {
[_subItems addObject:subItem];
}
}
_type = type;
_needsLocalization = needsLocalization;
_switchBarView = [[UIView alloc] initForAutoLayout];
@ -45,7 +59,6 @@
_switchBarLabel = [[UILabel alloc] initForAutoLayout];
[_switchBarLabel setTextColor:[@"999999" colorFromHex]];
[_switchBarLabel setText:NSLocalizedString(@"Distance", @"")];
[_switchBarView addSubview:_switchBarLabel];
_itemSwich = [[UISwitch alloc] initForAutoLayout];
@ -62,10 +75,43 @@
[self addSubview:_contentView];
_HUD = [[UIView alloc] initForAutoLayout];
<[_HUD setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.25]];
[_contentView addSubview:_HUD];
switch (_type) {
case TabBarPickerSubItemsViewTypeDateAndTime: {
break;
}
case TabBarPickerSubItemsViewTypeCheckBox: {
break;
}
case TabBarPickerSubItemsViewTypeDistance: {
_pickerView = [[UIPickerView alloc] initForAutoLayout];
[_pickerView setDelegate:self];
[_pickerView setDataSource:self];
[_contentView addSubview:_pickerView];
break;
}
case TabBarPickerSubItemsViewTypePrice: {
break;
}
default: {
break;
}
}
if (_needsLocalization) {
_localizationView = [[UIView alloc] initForAutoLayout];
[_localizationView setBackgroundColor:[UIColor purpleColor]];
[_localizationView setBackgroundColor:[UIColor whiteColor]];
[_localizationView setAlpha:0];
_localizationButton = [[UIButton alloc] initForAutoLayout];
@ -96,9 +142,21 @@
- (void) layoutSubviews {
//NSAssert(_dataSource, @"TabBarPickerSubItemsView needs datasource");
if (_needsLocalization) {
[UIView animateWithDuration:0.5 animations:^{
[_localizationView setAlpha:[[NSNumber numberWithBool:[[SharedLocationManager sharedManager] localizationIsAuthorized]] floatValue]];
[_localizationView setAlpha:[[NSNumber numberWithBool:![[SharedLocationManager sharedManager] localizationIsAuthorized]] floatValue]];
if ([[SharedLocationManager sharedManager] localizationIsAuthorized]) {
[_itemSwich setUserInteractionEnabled:[[SharedLocationManager sharedManager] localizationIsAuthorized]];
}
else {
[_itemSwich setUserInteractionEnabled:[[SharedLocationManager sharedManager] localizationIsAuthorized]];
[_itemSwich setOn:[[SharedLocationManager sharedManager] localizationIsAuthorized]];
}
}];
}
if (!_didSetupConstraints) {
@ -121,6 +179,11 @@
[_contentView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self];
[_contentView autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_HUD autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:_contentView];
[_HUD autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:_contentView];
[_HUD autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_HUD autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:_contentView];
if (_needsLocalization) {
[_localizationView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:_contentView];
@ -134,6 +197,7 @@
[_localizationButton autoSetDimension:ALDimensionHeight toSize:44 relation:NSLayoutRelationLessThanOrEqual];
[_localizationButton autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self withMultiplier:0.8];
}
_didSetupConstraints = YES;
}
@ -170,12 +234,13 @@
- (void)changeSwitch:(UISwitch*)sender{
[_HUD setAlpha:[[NSNumber numberWithBool:![sender isOn]] floatValue]];
if([sender isOn]){
NSLog(@"Switch is ON");
} else{
NSLog(@"Switch is OFF");
}
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
@ -188,4 +253,53 @@
[super touchesBegan: touches withEvent:event];
}
- (void) setItemName:(NSString *) itemName {
[_switchBarLabel setText:itemName];
}
#pragma mark UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
if ([_subItems count] > 0) {
[(TabBarSubItem*)[_subItems firstObject] numberOfValues];
}
return 0;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
}
#pragma mark -
#pragma mark UIPickerViewDelegate
/*
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
}
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
}
*/
#pragma mark -
@end

View File

@ -12,8 +12,12 @@
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) UIButton *subItemButton;
@property (nonatomic, strong) id value;
@property (nonatomic, strong) id firstValue;
@property (nonatomic, strong) id secondValue;
+ (instancetype) tabBarSubItemWithName:(NSString*)name andValue:(id) value;;
+ (instancetype) tabBarSubItemWithName:(NSString*)name andValue:(id) value;
+ (instancetype) tabBarSubItemWithName:(NSString*)name firstValue:(id) firstValue secondValue:(id) secondValue;
- (NSUInteger) numberOfValues;
@end

View File

@ -19,23 +19,26 @@
@implementation TabBarSubItem
- (instancetype) initWithName:(NSString *) name andValue:(id)value {
- (instancetype) initWithName:(NSString *) name firstValue:(id)firstValue secondValue:(id) secondValue {
self = [self initForAutoLayout];
if (self) {
//[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
_name = name;
_subItemButton = [[UIButton alloc] initForAutoLayout];
[_subItemButton setTitle:_name forState:UIControlStateNormal];
_value = value;
_firstValue = ( firstValue ? firstValue : @"");
_secondValue = ( secondValue ? secondValue : @"");
}
return self;
}
+ (instancetype) tabBarSubItemWithName:(NSString*)name andValue:(id)value {
return [[self alloc] initWithName:name andValue:value];
return [[self alloc] initWithName:name firstValue:value secondValue:nil];
}
+ (instancetype) initWithName:(NSString *) name firstValue:(id)firstValue secondValue:(id) secondValue {
return [[self alloc] initWithName:name firstValue:firstValue secondValue:secondValue];
}
- (void) setName:(NSString *)name {
@ -43,12 +46,18 @@
[_subItemButton setTitle:_name forState:UIControlStateNormal];
}
- (NSUInteger) numberOfValues {
NSUInteger response = 0;
- (void)deviceOrientationDidChange:(NSNotification *)notification {
//Obtain current device orientation
_orientation = [[UIDevice currentDevice] orientation];
if (_firstValue) {
response++;
}
[self layoutSubviews];
if (_secondValue) {
response++;
}
return response;
}
- (void) layoutSubviews {

View File

@ -45,7 +45,7 @@ typedef enum {
// Time it takes to scroll to next page
@property (nonatomic) CGFloat scrollingTime;
@property (nonatomic) NSUInteger currentPage;
@property (nonatomic) NSInteger currentPage;
@property (nonatomic, assign) id<MMCPSScrollViewDelegate> MMCPSDelegate;