no message
This commit is contained in:
1 parent
6c0f2bbae5
commit
4d7c6109a6
32 files changed
+1487
-1002
No files matched your search
@@ -8,6 +8,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "TabBarSubItem.h"
|
||||
#import "TabBarPickerSubItemsView.h"
|
||||
|
||||
@class TabBarItem;
|
||||
|
||||
@@ -25,14 +26,17 @@
|
||||
* Represents the image visible in picker when item is not selected.
|
||||
*/
|
||||
@property (nonatomic, strong) UIImage *image;
|
||||
|
||||
/**
|
||||
* Represents the image visible in picker when item is selected.
|
||||
*/
|
||||
@property (nonatomic, strong) UIImage *selectedImage;
|
||||
|
||||
/**
|
||||
* Represents the image visible in picker when item is highlited.
|
||||
*/
|
||||
@property (nonatomic, strong) UIImage *highlightedImage;
|
||||
|
||||
/**
|
||||
* Represents the color of picker item when is highlited.
|
||||
*/
|
||||
@@ -42,11 +46,15 @@
|
||||
* Represents the name of the item that can be shown in picker.
|
||||
*/
|
||||
@property (nonatomic, strong) NSString *itemName;
|
||||
|
||||
/**
|
||||
* Represents the sub items that appeare when you select the item in picker.
|
||||
*/
|
||||
@property (nonatomic, strong) NSMutableArray *subItems;
|
||||
@property (nonatomic, strong) TabBarPickerSubItemsView *itemSubView;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, assign) id<TabBarItemDelegate> delegate;
|
||||
|
||||
/**
|
||||
@@ -56,8 +64,13 @@
|
||||
*
|
||||
* @return <#return value description#>
|
||||
*/
|
||||
- (instancetype) initWithSubItems:(NSArray*) array;
|
||||
- (instancetype) initWithSubItemView:(TabBarPickerSubItemsView*) itemSubView;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @param highlighted <#highlighted description#>
|
||||
*/
|
||||
- (void) setHighlighted:(BOOL) highlighted;
|
||||
|
||||
|
||||
|
||||
+30
-24
@@ -10,6 +10,7 @@
|
||||
#import <PureLayout/PureLayout.h>
|
||||
#import "NSString+HexColor.h"
|
||||
#import "UIButton+BackgroundColor.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface TabBarItem()
|
||||
|
||||
@@ -17,32 +18,34 @@
|
||||
@property (nonatomic, strong) UIButton *itemButton;
|
||||
@property (nonatomic) UIDeviceOrientation orientation;
|
||||
@property (nonatomic, assign) BOOL didSetupConstraints;
|
||||
@property (nonatomic, strong) UIView *switchBarView;
|
||||
@property (nonatomic, strong) UISwitch *itemSwich;
|
||||
@property (nonatomic, strong) UILabel *switchBarLabel;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TabBarItem
|
||||
|
||||
- (instancetype) initWithSubItems:(NSArray*) array {
|
||||
- (instancetype) initWithSubItemView:(TabBarPickerSubItemsView*) itemSubView {
|
||||
|
||||
return [self initWithSubItemView:itemSubView needLocalization:NO];
|
||||
}
|
||||
|
||||
- (instancetype) initWithSubItemView:(TabBarPickerSubItemsView*) itemSubView needLocalization:(BOOL) needLocalitazion {
|
||||
self = [self initForAutoLayout];
|
||||
if (self) {
|
||||
NSAssert(array, @"SubItemsArray cannot be nil");
|
||||
NSAssert(itemSubView, @"itemSubView cannot be nil");
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
|
||||
|
||||
_orientation = [[UIDevice currentDevice] orientation];
|
||||
_itemSubView = itemSubView;
|
||||
|
||||
_itemButton = [[UIButton alloc] initForAutoLayout];
|
||||
[_itemButton addTarget:self action:@selector(itemButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_itemButton setBackgroundColor:[@"ff4e50" colorFromHex] forState:UIControlStateHighlighted];
|
||||
|
||||
[self addSubview:_itemButton];
|
||||
|
||||
_subItems = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSObject *subItem in array) {
|
||||
if ([subItem isKindOfClass:[TabBarSubItem class]]) {
|
||||
[_subItems addObject:subItem];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -51,9 +54,10 @@
|
||||
|
||||
//[_itemButton autoPinEdgesToSuperviewMargins];
|
||||
if (!_didSetupConstraints) {
|
||||
[_itemButton autoCenterInSuperview];
|
||||
[_itemButton autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self];
|
||||
[_itemButton autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
||||
[_itemButton autoCenterInSuperview];
|
||||
[_itemButton autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self];
|
||||
[_itemButton autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
||||
|
||||
_didSetupConstraints = YES;
|
||||
}
|
||||
}
|
||||
@@ -88,24 +92,26 @@
|
||||
|
||||
- (void) setHighlighted:(BOOL) highlighted {
|
||||
[_itemButton setHighlighted:highlighted];
|
||||
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isSelected]]);
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isHighlighted]]);
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isEnabled]]);
|
||||
NSLog(@"%ld",_itemButton.state);
|
||||
}
|
||||
|
||||
- (void) itemButtonTapped {
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(tabBarItemSelected:)]) {
|
||||
[_delegate tabBarItemSelected:self];
|
||||
}
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isSelected]]);
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isHighlighted]]);
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isEnabled]]);
|
||||
NSLog(@"%ld",_itemButton.state);
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.002 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[_itemButton setHighlighted:YES];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.00001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self setHighlighted:YES];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)openSettings
|
||||
{
|
||||
BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
|
||||
if (canOpenSettings) {
|
||||
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
||||
[[UIApplication sharedApplication] openURL:url];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
+67
-52
@@ -9,7 +9,7 @@
|
||||
#import "TabBarPicker.h"
|
||||
#import <PureLayout/PureLayout.h>
|
||||
#import "TabBarPickerSubItemsView.h"
|
||||
#import "MMCPSScrollView.h"
|
||||
#import "ToucheableScrollView.h"
|
||||
#import <UIView-Overlay/UIView+Overlay.h>
|
||||
#import "NSString+HexColor.h"
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
@property (nonatomic, strong) NSLayoutConstraint *hideConstraint;
|
||||
@property (nonatomic, strong) NSMutableArray *tabBarItemsConstraints;
|
||||
@property (nonatomic, strong) TabBarItem *selectedTabBarItem;
|
||||
@property (nonatomic, strong) MMCPSScrollView *subItemScrollView;
|
||||
|
||||
@property (nonatomic, strong) ToucheableScrollView *subItemScrollView;
|
||||
@property (assign, nonatomic) int totalPages;
|
||||
|
||||
@end
|
||||
|
||||
@@ -46,7 +48,7 @@
|
||||
|
||||
self = [self initForAutoLayout];
|
||||
if (self) {
|
||||
|
||||
[self setUserInteractionEnabled:YES];
|
||||
_itemSpacing = 10;
|
||||
_layoutRelation = relation;
|
||||
_position = position;
|
||||
@@ -77,47 +79,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
_subItemScrollView = [[MMCPSScrollView alloc] initForAutoLayout];
|
||||
[_subItemScrollView setType:MMCPSScrollHorizontal];
|
||||
[_subItemScrollView setMMCPSDelegate:self];
|
||||
_subItemScrollView = [[ToucheableScrollView alloc] initForAutoLayout];
|
||||
[_subItemScrollView setPagingEnabled:YES];
|
||||
[_subItemScrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
|
||||
[_subItemScrollView setUserInteractionEnabled:YES];
|
||||
|
||||
[self addSubview:_subItemScrollView];
|
||||
|
||||
if ([_tabBarItems count] > 0) {
|
||||
int i = 0;
|
||||
for (TabBarItem *item in _tabBarItems) {
|
||||
TabBarPickerSubItemsView *subItemSelector = [[TabBarPickerSubItemsView alloc] init];
|
||||
[subItemSelector setDelegate:self];
|
||||
switch (i) {
|
||||
case 0:
|
||||
[subItemSelector setBackgroundColor:[UIColor lightGrayColor]];
|
||||
break;
|
||||
case 1:{
|
||||
[subItemSelector setBackgroundColor:[UIColor redColor]];
|
||||
}
|
||||
break;
|
||||
case 2:{
|
||||
[subItemSelector setBackgroundColor:[UIColor greenColor]];
|
||||
}
|
||||
break;
|
||||
case 3: {
|
||||
[subItemSelector setBackgroundColor:[UIColor yellowColor]];
|
||||
}
|
||||
break;
|
||||
default:{
|
||||
[subItemSelector setBackgroundColor:[UIColor blueColor]];
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
[_subItemScrollView addSubview:subItemSelector];
|
||||
|
||||
[_subItemSelectors addObject:subItemSelector];
|
||||
}
|
||||
[_subItemScrollView setPageSize:1];
|
||||
}
|
||||
}
|
||||
|
||||
[self updateConstraintsIfNeeded];
|
||||
@@ -126,7 +93,7 @@
|
||||
}
|
||||
|
||||
- (void) layoutSubviews {
|
||||
|
||||
|
||||
if (!_didSetupConstraints) {
|
||||
|
||||
switch (_position) {
|
||||
@@ -185,23 +152,71 @@
|
||||
|
||||
[_tabBarItemsConstraints addObjectsFromArray:[_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:_itemSpacing insetSpacing:YES matchedSizes:YES]];
|
||||
|
||||
|
||||
|
||||
[_subItemScrollView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
||||
[_subItemScrollView autoSetDimension:ALDimensionHeight toSize:343];
|
||||
[_subItemScrollView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:[_tabBarItems firstObject]];
|
||||
[_subItemScrollView autoAlignAxisToSuperviewAxis:ALAxisVertical];
|
||||
|
||||
//[_subItemScrollView setPageSize:343];
|
||||
[_subItemScrollView setSegmentSize:[[UIScreen mainScreen] bounds].size.width];
|
||||
if ([_tabBarItems count] > 0) {
|
||||
int i = 0;
|
||||
|
||||
TabBarItem *prevItem;
|
||||
for (TabBarItem *item in _tabBarItems) {
|
||||
|
||||
if ([item itemSubView]) {
|
||||
|
||||
[[item itemSubView] setDelegate:self];
|
||||
[[item itemSubView] setTabBarItemReference:self];
|
||||
switch (i) {
|
||||
case 0:
|
||||
[[item itemSubView] setBackgroundColor:[UIColor lightGrayColor]];
|
||||
break;
|
||||
case 1:{
|
||||
[[item itemSubView] setBackgroundColor:[UIColor redColor]];
|
||||
}
|
||||
break;
|
||||
case 2:{
|
||||
[[item itemSubView] setBackgroundColor:[UIColor greenColor]];
|
||||
}
|
||||
break;
|
||||
case 3: {
|
||||
[[item itemSubView] setBackgroundColor:[UIColor yellowColor]];
|
||||
}
|
||||
break;
|
||||
default:{
|
||||
[[item itemSubView] setBackgroundColor:[UIColor blueColor]];
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
[_subItemScrollView addSubview:[item itemSubView]];
|
||||
|
||||
[_subItemSelectors addObject:[item itemSubView]];
|
||||
|
||||
if (!prevItem) {
|
||||
// Align to contentView
|
||||
[pageLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft];
|
||||
} else {
|
||||
// Align to prev label
|
||||
[pageLabel autoConstrainAttribute:ALAttributeLeading toAttribute:ALAttributeTrailing ofView:prevLabel];
|
||||
}
|
||||
|
||||
if (i == pages - 1) {
|
||||
// Last page
|
||||
[pageLabel autoPinEdgeToSuperviewEdge:ALEdgeRight];
|
||||
}
|
||||
|
||||
prevItem = item;
|
||||
}
|
||||
}
|
||||
[_subItemScrollView setPageSize:1];
|
||||
}
|
||||
|
||||
[_subItemSelectors autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:0 insetSpacing:YES matchedSizes:YES];
|
||||
[_subItemSelectors autoSetViewsDimension:ALDimensionHeight toSize:343];
|
||||
[_subItemSelectors autoSetViewsDimension:ALDimensionWidth toSize:[[UIScreen mainScreen] bounds].size.width];
|
||||
//[_subItemSelectors autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:0 insetSpacing:YES matchedSizes:YES];
|
||||
|
||||
[[_subItemSelectors firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
//[[_subItemSelectors firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
|
||||
[_subItemScrollView setContentSize:CGSizeMake([_subItemSelectors count]*[[UIScreen mainScreen] bounds].size.width , 343)];
|
||||
//[_subItemScrollView layoutIfNeeded];
|
||||
|
||||
}
|
||||
break;
|
||||
@@ -209,7 +224,7 @@
|
||||
|
||||
|
||||
_didSetupConstraints = YES;
|
||||
|
||||
|
||||
[self updateConstraintsIfNeeded];
|
||||
}
|
||||
}
|
||||
@@ -374,7 +389,7 @@
|
||||
}
|
||||
_selectedTabBarItem = selectedItem;
|
||||
|
||||
[_subItemScrollView scrollToPage:[_tabBarItems indexOfObject:_selectedTabBarItem]];
|
||||
[_subItemScrollView scrollToPage:[_tabBarItems indexOfObject:_selectedTabBarItem]+1];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TabBarItem.h"
|
||||
|
||||
@class TabBarItem;
|
||||
@class TabBarSubItem;
|
||||
@class TabBarPickerSubItemsView;
|
||||
|
||||
typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
|
||||
@@ -23,7 +24,7 @@ typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
|
||||
|
||||
@required
|
||||
|
||||
- (void) tabarPickerSubItemsView:(TabBarPickerSubItemsView*) tabarPickerSubItemsView didSelect:(TabBarItem*) item;
|
||||
- (void) tabarPickerSubItemsView:(TabBarPickerSubItemsView*) tabarPickerSubItemsView didSelectTabBarSubItem:(TabBarSubItem*) subItem forTabBarItem:(TabBarItem*) item;
|
||||
|
||||
@end
|
||||
|
||||
@@ -33,6 +34,21 @@ typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, assign) id<TabBarPickerSubItemsViewDelegate> delegate;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic) BOOL needsLocalization;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong) UIView *localizationView;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong) TabBarItem *tabBarItemReference;
|
||||
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems;
|
||||
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems needsLocalization:(BOOL) needsLocalization;
|
||||
|
||||
@end
|
||||
@@ -8,23 +8,83 @@
|
||||
|
||||
#import "TabBarPickerSubItemsView.h"
|
||||
#import <PureLayout/PureLayout.h>
|
||||
#import "TabBarItem.h"
|
||||
#import "NSString+HexColor.h"
|
||||
#import "SharedLocationManager.h"
|
||||
|
||||
@interface TabBarPickerSubItemsView()
|
||||
|
||||
@property (nonatomic, assign) BOOL didSetupConstraints;
|
||||
@property (nonatomic) TabBarPickerSubItemsViewType type;
|
||||
@property (nonatomic, strong) NSMutableArray *elementsArray;
|
||||
@property (nonatomic, strong) NSMutableArray *subItems;
|
||||
@property (nonatomic, strong) UIView *switchBarView;
|
||||
@property (nonatomic, strong) UISwitch *itemSwich;
|
||||
@property (nonatomic, strong) UILabel *switchBarLabel;
|
||||
@property (nonatomic, strong) UIButton *localizationButton;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TabBarPickerSubItemsView
|
||||
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type andElements:(NSArray*) elements {
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems {
|
||||
return [self initWithType:type subItems:subItems needsLocalization:NO];
|
||||
}
|
||||
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems needsLocalization:(BOOL) needsLocalization{
|
||||
|
||||
self = [self initForAutoLayout];
|
||||
|
||||
if (self) {
|
||||
[self setUserInteractionEnabled:YES];
|
||||
_type = type;
|
||||
_elementsArray = [[NSMutableArray alloc] initWithArray:elements];
|
||||
_needsLocalization = needsLocalization;
|
||||
_switchBarView = [[UIView alloc] initForAutoLayout];
|
||||
[_switchBarView setBackgroundColor:[@"f7f7f7" colorFromHex]];
|
||||
|
||||
_switchBarLabel = [[UILabel alloc] initForAutoLayout];
|
||||
[_switchBarLabel setTextColor:[@"999999" colorFromHex]];
|
||||
[_switchBarLabel setText:NSLocalizedString(@"Distance", @"")];
|
||||
[_switchBarView addSubview:_switchBarLabel];
|
||||
|
||||
_itemSwich = [[UISwitch alloc] initForAutoLayout];
|
||||
[_itemSwich setOnTintColor:[@"ff4e50" colorFromHex]];
|
||||
|
||||
[_itemSwich.layer setBorderWidth:2];
|
||||
[_itemSwich.layer setBorderColor:[[@"cccccc" colorFromHex] CGColor]];
|
||||
[_itemSwich.layer setCornerRadius:_itemSwich.frame.size.height/2];
|
||||
[_itemSwich setUserInteractionEnabled:YES];
|
||||
[_itemSwich addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
|
||||
[_switchBarView addSubview:_itemSwich];
|
||||
|
||||
if (_needsLocalization) {
|
||||
|
||||
_localizationView = [[UIView alloc] initForAutoLayout];
|
||||
[_localizationView setBackgroundColor:[UIColor purpleColor]];
|
||||
[_localizationView setAlpha:0];
|
||||
|
||||
|
||||
_localizationButton = [[UIButton alloc] initForAutoLayout];
|
||||
[_localizationButton setTitle:NSLocalizedString(@"ATTIVA LOCALIZZAZIONE DISPOSITIVO", @"") forState:UIControlStateNormal];
|
||||
[_localizationButton addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_localizationButton setBackgroundColor:[UIColor whiteColor]];
|
||||
[_localizationButton.layer setBorderColor:[[@"ff4e50" colorFromHex] CGColor]];
|
||||
[_localizationButton.layer setBorderWidth:1];
|
||||
[_localizationButton setTitleColor:[@"ff4e50" colorFromHex] forState:UIControlStateNormal];
|
||||
[_localizationButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
|
||||
[_localizationButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:14]];
|
||||
|
||||
[_localizationView addSubview:_localizationButton];
|
||||
|
||||
[self addSubview:_localizationView];
|
||||
}
|
||||
|
||||
/*_subItems = [[NSMutableArray alloc] init];
|
||||
for (NSObject *subItem in subItems) {
|
||||
if ([subItem isKindOfClass:[TabBarSubItem class]]) {
|
||||
[_subItems addObject:subItem];
|
||||
}
|
||||
}*/
|
||||
[self addSubview:_switchBarView];
|
||||
}
|
||||
|
||||
[self updateConstraintsIfNeeded];
|
||||
@@ -35,13 +95,77 @@
|
||||
|
||||
- (void) layoutSubviews {
|
||||
|
||||
[UIView animateWithDuration:0.5 animations:^{
|
||||
[_localizationView setAlpha:[[NSNumber numberWithBool:[[SharedLocationManager sharedManager] localizationIsAuthorized]] floatValue]];
|
||||
}];
|
||||
|
||||
if (!_didSetupConstraints) {
|
||||
|
||||
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual];
|
||||
[self autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual];
|
||||
|
||||
[_switchBarView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview];
|
||||
[_switchBarView autoSetDimension:ALDimensionHeight toSize:40];
|
||||
[_switchBarView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self];
|
||||
[_switchBarView autoAlignAxisToSuperviewAxis:ALAxisVertical];
|
||||
|
||||
[_switchBarLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self withOffset:20];
|
||||
[_switchBarLabel autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
|
||||
[_itemSwich autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:_switchBarView withOffset:-20];
|
||||
[_itemSwich autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
|
||||
[_localizationView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_itemSwich withOffset:4];
|
||||
[_localizationView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self];
|
||||
[_localizationView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
||||
|
||||
[_localizationButton autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
[_localizationButton autoAlignAxisToSuperviewAxis:ALAxisVertical];
|
||||
[_localizationButton autoSetDimension:ALDimensionHeight toSize:44 relation:NSLayoutRelationLessThanOrEqual];
|
||||
[_localizationButton autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self withMultiplier:0.8];
|
||||
|
||||
_didSetupConstraints = YES;
|
||||
}
|
||||
NSLog(@"%f %f",self.frame.size.width,self.frame.size.height);
|
||||
NSLog(@"%f %f",_switchBarView.frame.size.width,_switchBarView.frame.size.height);
|
||||
[_localizationButton.layer setCornerRadius:_localizationButton.frame.size.height/2];
|
||||
}
|
||||
|
||||
- (void) enableLocalizationWithView:(UIView *) localizationView {
|
||||
_needsLocalization = YES;
|
||||
_localizationView = localizationView;
|
||||
|
||||
[self addSubview:_localizationView];
|
||||
}
|
||||
|
||||
|
||||
- (void)openSettings
|
||||
{
|
||||
BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
|
||||
if (canOpenSettings) {
|
||||
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
||||
[[UIApplication sharedApplication] openURL:url];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)changeSwitch:(UISwitch*)sender{
|
||||
|
||||
if([sender isOn]){
|
||||
NSLog(@"Switch is ON");
|
||||
} else{
|
||||
NSLog(@"Switch is OFF");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
|
||||
{
|
||||
[super touchesEnded: touches withEvent: event];
|
||||
}
|
||||
|
||||
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
|
||||
[super touchesBegan: touches withEvent:event];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -12,7 +12,8 @@
|
||||
|
||||
@property (nonatomic, strong) NSString *name;
|
||||
@property (nonatomic, strong) UIButton *subItemButton;
|
||||
@property (nonatomic, strong) id value;
|
||||
|
||||
+ (instancetype) tabBarSubItemWithName:(NSString*)name;
|
||||
+ (instancetype) tabBarSubItemWithName:(NSString*)name andValue:(id) value;;
|
||||
|
||||
@end
|
||||
@@ -19,28 +19,28 @@
|
||||
@implementation TabBarSubItem
|
||||
|
||||
|
||||
- (instancetype) initWithName:(NSString *) name {
|
||||
- (instancetype) initWithName:(NSString *) name andValue:(id)value {
|
||||
|
||||
self = [self initForAutoLayout];
|
||||
if (self) {
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
|
||||
//[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
|
||||
|
||||
_name = name;
|
||||
|
||||
_subItemButton = [[UIButton alloc] initForAutoLayout];
|
||||
[_subItemButton setTitle:_name forState:UIControlStateNormal];
|
||||
_value = value;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype) tabBarSubItemWithName:(NSString*)name {
|
||||
return [[self alloc] initWithName:name];
|
||||
+ (instancetype) tabBarSubItemWithName:(NSString*)name andValue:(id)value {
|
||||
return [[self alloc] initWithName:name andValue:value];
|
||||
}
|
||||
|
||||
- (void) setName:(NSString *)name {
|
||||
_name = name;
|
||||
[_subItemButton setTitle:name forState:UIControlStateNormal];
|
||||
[_subItemButton setTitle:_name forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
if (self) {
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
[self setUserInteractionEnabled:YES];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -291,6 +292,7 @@
|
||||
|
||||
- (void)addSubview:(UIView *)view {
|
||||
[super addSubview:view];
|
||||
[view setUserInteractionEnabled:YES];
|
||||
|
||||
int currentLowestPoint = [self CGRectOrigin:_bottomComponent] + [self CGRectSize:_bottomComponent];
|
||||
int viewLowestPoint = [self frameOrigin:view] + [self frameSize:view];
|
||||
@@ -318,4 +320,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
|
||||
{
|
||||
// If not dragging, send event to next responder
|
||||
if (!self.dragging) {
|
||||
[self.nextResponder.nextResponder touchesEnded: touches withEvent:event];
|
||||
}
|
||||
else
|
||||
[super touchesEnded: touches withEvent: event];
|
||||
|
||||
}
|
||||
|
||||
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
|
||||
if (!self.dragging) {
|
||||
[self.nextResponder.nextResponder touchesBegan: touches withEvent:event];
|
||||
}
|
||||
else
|
||||
[super touchesBegan: touches withEvent:event];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// SharedLocationManager.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 15/07/15.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
|
||||
@interface SharedLocationManager : NSObject <CLLocationManagerDelegate>{
|
||||
CLLocationManager *locationManager;
|
||||
CLLocation *currentLocation;
|
||||
}
|
||||
|
||||
+ (id) sharedManager;
|
||||
- (void) setCurrentLocation;
|
||||
- (CLLocation*) getCurrentLocation;
|
||||
- (BOOL) locationIsSet;
|
||||
- (BOOL) localizationIsAuthorized;
|
||||
- (CLAuthorizationStatus) localizationAuthorizationStatus;
|
||||
|
||||
@end
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// SharedLocationManager.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 15/07/15.
|
||||
//
|
||||
|
||||
#import "SharedLocationManager.h"
|
||||
|
||||
@implementation SharedLocationManager
|
||||
+ (id)sharedManager {
|
||||
static SharedLocationManager *sharedMyManager = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedMyManager = [[self alloc] init];
|
||||
});
|
||||
return sharedMyManager;
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
if (self = [super init]) {
|
||||
locationManager = [[CLLocationManager alloc] init];
|
||||
locationManager.delegate = self;
|
||||
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
|
||||
if([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0)
|
||||
{
|
||||
[CLLocationManager authorizationStatus];
|
||||
}
|
||||
else {
|
||||
[locationManager requestWhenInUseAuthorization];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (void)setCurrentLocation {
|
||||
|
||||
[locationManager startUpdatingLocation];
|
||||
}
|
||||
#pragma mark - CLLocationManagerDelegate
|
||||
|
||||
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
|
||||
{
|
||||
[locationManager stopUpdatingLocation];
|
||||
}
|
||||
|
||||
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
|
||||
{
|
||||
if (newLocation != nil) {
|
||||
currentLocation = newLocation;
|
||||
}
|
||||
[locationManager stopUpdatingLocation];
|
||||
}
|
||||
|
||||
-(BOOL)locationIsSet {
|
||||
if(currentLocation != nil)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(CLLocation*)getCurrentLocation {
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
- (BOOL) localizationIsAuthorized {
|
||||
if ( [CLLocationManager locationServicesEnabled] == NO || [self localizationAuthorizationStatus] == kCLAuthorizationStatusDenied)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (CLAuthorizationStatus) localizationAuthorizationStatus {
|
||||
return [CLLocationManager authorizationStatus];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// ToucheableScrollView.m
|
||||
//
|
||||
//
|
||||
// Created by Mario Nolassi on 11/16/11.
|
||||
// Copyright (c) 2011 meedori. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ToucheableScrollView : UIScrollView
|
||||
|
||||
@end
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// ToucheableScrollView.m
|
||||
//
|
||||
//
|
||||
// Created by Mario Nolassi on 11/16/11.
|
||||
// Copyright (c) 2011 meedori. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ToucheableScrollView.h"
|
||||
|
||||
@implementation ToucheableScrollView
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
|
||||
{
|
||||
// If not dragging, send event to next responder
|
||||
if (!self.dragging) {
|
||||
if ([self.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)]) {
|
||||
[self.nextResponder touchesEnded: touches withEvent:event];
|
||||
}
|
||||
if ([self.nextResponder.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)]) {
|
||||
[self.nextResponder.nextResponder touchesEnded: touches withEvent:event];
|
||||
}
|
||||
if ([self.nextResponder.nextResponder.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)]) {
|
||||
[self.nextResponder.nextResponder.nextResponder touchesEnded: touches withEvent:event];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[super touchesEnded: touches withEvent: event];
|
||||
}
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user