Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Classes/MMPopupView.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ - (MMPopupBlock)alertShowAnimation
[self mas_updateConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.attachedView).centerOffset(CGPointMake(0, self.withKeyboard?-216/2:0));
}];
[self layoutIfNeeded];
[self.superview layoutIfNeeded];

self.layer.transform = CATransform3DMakeScale(1.2f, 1.2f, 1.0f);
self.alpha = 0.0f;
Expand Down Expand Up @@ -225,7 +225,7 @@ - (MMPopupBlock)sheetShowAnimation
make.centerX.equalTo(self.attachedView);
make.bottom.equalTo(self.attachedView.mas_bottom).offset(self.attachedView.frame.size.height);
}];
[self layoutIfNeeded];
[self.superview layoutIfNeeded];

[UIView animateWithDuration:self.animationDuration
delay:0
Expand All @@ -236,7 +236,7 @@ - (MMPopupBlock)sheetShowAnimation
make.bottom.equalTo(self.attachedView.mas_bottom).offset(0);
}];

[self layoutIfNeeded];
[self.superview layoutIfNeeded];

}
completion:^(BOOL finished) {
Expand Down Expand Up @@ -267,12 +267,12 @@ - (MMPopupBlock)sheetHideAnimation
make.bottom.equalTo(self.attachedView.mas_bottom).offset(self.attachedView.frame.size.height);
}];

[self layoutIfNeeded];
[self.superview layoutIfNeeded];

}
completion:^(BOOL finished) {

[self removeFromSuperview];
[self.superview removeFromSuperview];

if ( self.hideCompletionBlock )
{
Expand All @@ -295,7 +295,7 @@ - (MMPopupBlock)customShowAnimation
[self mas_updateConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.attachedView).centerOffset(CGPointMake(0, -self.attachedView.bounds.size.height));
}];
[self layoutIfNeeded];
[self.superview layoutIfNeeded];

[UIView animateWithDuration:self.animationDuration
delay:0
Expand All @@ -308,7 +308,7 @@ - (MMPopupBlock)customShowAnimation
make.center.equalTo(self.attachedView).centerOffset(CGPointMake(0, self.withKeyboard?-216/2:0));
}];

[self layoutIfNeeded];
[self.superview layoutIfNeeded];

} completion:^(BOOL finished) {

Expand Down Expand Up @@ -338,7 +338,7 @@ - (MMPopupBlock)customHideAnimation
make.center.equalTo(self.attachedView).centerOffset(CGPointMake(0, self.attachedView.bounds.size.height));
}];

[self layoutIfNeeded];
[self.superview layoutIfNeeded];

} completion:^(BOOL finished) {

Expand Down
61 changes: 61 additions & 0 deletions MMPopupView/MMAddress/MMAddressData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// MMAddressModel.h
// MMPopupView
//
// Created by Jone on 15/10/24.
// Copyright © 2015年 LJC. All rights reserved.
//

#import <Foundation/Foundation.h>

/**
* 城市模型
*/
@interface MMAddress : NSObject

@property (nonatomic, copy) NSString *aProvince;
@property (nonatomic, copy) NSString *aCity;
@property (nonatomic, copy) NSString *aDistrict;

- (instancetype)initWithProvince:(NSString *)province city:(NSString *)city district:(NSString *)district;

@end



@interface MMAddressData : NSObject

/**
* 当前选中的省、市、县列表
*/
@property (nonatomic, readonly) NSArray *provinces;
@property (nonatomic, readonly) NSArray *citys;
@property (nonatomic, readonly) NSArray *districts;

/**
* 当前选中的省、市、县
*/
@property (nonatomic, readonly) MMAddress *selectedAddress;

/**
* 滚动省,刷新市、县
*
* @param row 当前省row
*/
- (void)reloadCityAndDistrictAtRow:(NSInteger)row;

/**
* 滚动市,刷新县
*
* @param row 当前市row
*/
- (void)reloadCityAtRow:(NSInteger)row;

/**
* 滚动县
*
* @param row 当前县row
*/
- (void)reloadDistrictAtRow:(NSInteger)row;

@end
176 changes: 176 additions & 0 deletions MMPopupView/MMAddress/MMAddressData.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
//
// MMAddressModel.m
// MMPopupView
//
// Created by Jone on 15/10/24.
// Copyright © 2015年 LJC. All rights reserved.
//

#import "MMAddressData.h"

@implementation MMAddress

- (instancetype)initWithProvince:(NSString *)province city:(NSString *)city district:(NSString *)district
{
self = [super init];

if (self) {
_aProvince = province;
_aCity = city;
_aDistrict = district;
}

return self;
}

@end



@interface MMAddressData()

@property (nonatomic, strong) NSDictionary *chinaAddressDict;

@property (nonatomic, readwrite) NSArray *provinces;
@property (nonatomic, readwrite) NSArray *citys;
@property (nonatomic, readwrite) NSArray *districts;

@property (nonatomic, readwrite) MMAddress *selectedAddress;

@end

@implementation MMAddressData

- (instancetype)init
{
self = [super init];

if (self) {
[self configureInitializationData];
}

return self;
}

- (void)configureInitializationData
{

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"china_address" ofType:@"plist"];
self.chinaAddressDict = [[NSDictionary alloc] initWithContentsOfFile:filePath]; // 获取到地址字典

NSArray *components = [self.chinaAddressDict allKeys];
NSArray *sortedArray = [components sortedArrayUsingComparator: ^(id obj1, id obj2) {

if ([obj1 integerValue] > [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedDescending;
}

if ([obj1 integerValue] < [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];

NSMutableArray *provinceTmp = [[NSMutableArray alloc] init];
for (int i=0; i<[sortedArray count]; i++) {
NSString *index = [sortedArray objectAtIndex:i];
NSArray *tmp = [[self.chinaAddressDict objectForKey: index] allKeys];
[provinceTmp addObject: [tmp objectAtIndex:0]];
}

self.provinces = [[NSArray alloc] initWithArray: provinceTmp];// 获取初始省列表

NSString *index = [sortedArray objectAtIndex:0];
NSString *selected = [self.provinces objectAtIndex:0];
NSDictionary *dic = [NSDictionary dictionaryWithDictionary: [[self.chinaAddressDict objectForKey:index]objectForKey:selected]];

NSArray *cityArray = [dic allKeys];
NSDictionary *cityDic = [NSDictionary dictionaryWithDictionary: [dic objectForKey: [cityArray objectAtIndex:0]]];
NSArray *cityKeys = [cityDic allKeys];
self.citys = [[NSArray alloc] initWithArray:cityKeys]; // 获取初始市列表


NSString *selectedCity = [self.citys objectAtIndex: 0];
NSArray *dictricts = [cityDic objectForKey:selectedCity];
self.districts = [[NSArray alloc] initWithArray:dictricts]; // 获取选中县

// 初始化选中的地址
self.selectedAddress = [[MMAddress alloc] init];
self.selectedAddress.aProvince = _provinces.firstObject;
self.selectedAddress.aCity = _citys.firstObject;
self.selectedAddress.aDistrict = _districts.firstObject;
}

- (void)reloadCityAndDistrictAtRow:(NSInteger)row
{
self.selectedAddress.aProvince = _provinces[row];

NSDictionary *tmp = [NSDictionary dictionaryWithDictionary: [self.chinaAddressDict objectForKey: [NSString stringWithFormat:@"%ld", (long)row]]];
NSDictionary *dic = [NSDictionary dictionaryWithDictionary: [tmp objectForKey:_selectedAddress.aProvince]];
NSArray *cityArray = [dic allKeys];
if (cityArray.count == 0) {
return;
}
NSArray *sortedArray = [cityArray sortedArrayUsingComparator: ^(id obj1, id obj2) {

if ([obj1 integerValue] > [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedDescending;
}

if ([obj1 integerValue] < [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];

NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i=0; i<[sortedArray count]; i++) {
NSString *index = [sortedArray objectAtIndex:i];
NSArray *temp = [dic[index] allKeys];
[array addObject:temp[0]];
}

self.citys = [[NSArray alloc] initWithArray:array];
self.selectedAddress.aCity = _citys.firstObject;

NSDictionary *cityDic = [dic objectForKey:sortedArray[0]];
self.districts = [[NSArray alloc] initWithArray: [cityDic objectForKey:self.citys[0]]];
self.selectedAddress.aDistrict = _districts.firstObject;
}

- (void)reloadCityAtRow:(NSInteger)row
{
NSString *provinceIndex = [NSString stringWithFormat:@"%ld", (unsigned long)[self.provinces indexOfObject:_selectedAddress.aProvince]];
NSDictionary *tmp = [NSDictionary dictionaryWithDictionary:[self.chinaAddressDict objectForKey: provinceIndex]];
NSDictionary *dic = [NSDictionary dictionaryWithDictionary: [tmp objectForKey:_selectedAddress.aProvince]];
NSArray *dicKeyArray = [dic allKeys];
NSArray *sortedArray = [dicKeyArray sortedArrayUsingComparator: ^(id obj1, id obj2) {
if ([obj1 integerValue] > [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedDescending;
}

if ([obj1 integerValue] < [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];

NSDictionary *cityDic = [NSDictionary dictionaryWithDictionary: [dic objectForKey:[sortedArray objectAtIndex:row]]];
NSArray *cityKeyArray = [cityDic allKeys];

if (cityKeyArray.count == 0) {
return;
}

self.districts = [[NSArray alloc] initWithArray: [cityDic objectForKey:cityKeyArray[0]]];

// 更新选中的市、县
self.selectedAddress.aCity = cityKeyArray[0];
self.selectedAddress.aDistrict = _districts.firstObject;
}

- (void)reloadDistrictAtRow:(NSInteger)row
{
self.selectedAddress.aDistrict = _districts[row]; // 更新选中的县
}
@end
25 changes: 25 additions & 0 deletions MMPopupView/MMAddress/MMAddressView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// MMAdressView.h
// MMPopupView
//
// Created by Jone on 15/10/23.
// Copyright © 2015年 LJC. All rights reserved.
//

#import "MMPopupView.h"
#import "MMAddressData.h"

@interface MMAddressView : MMPopupView

@property (nonatomic, copy) void (^selectedAddress)(MMAddress *address);

/**
* 自定义初始化方法
*
* @param address 初始选中的地址
*
* @return MMAdressView实例
*/
- (instancetype)initWithAddress:(MMAddress *)address;

@end
Loading