diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo.xcodeproj/project.pbxproj b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo.xcodeproj/project.pbxproj index 6bb9b39..fa49bf9 100644 --- a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo.xcodeproj/project.pbxproj +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo.xcodeproj/project.pbxproj @@ -17,6 +17,9 @@ 4B32F1D11EEFE8A40066445B /* FirstViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F1D31EEFE8A40066445B /* FirstViewController.xib */; }; 4B32F1D81EEFE9850066445B /* SecondViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F1DA1EEFE9850066445B /* SecondViewController.xib */; }; 4B32F1E71EEFF38C0066445B /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F1E91EEFF38C0066445B /* Localizable.strings */; }; + 4B32F1FA1EF000220066445B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F1FC1EF000220066445B /* InfoPlist.strings */; }; + 4B32F2021EF002D90066445B /* ThirdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B32F2001EF002D90066445B /* ThirdViewController.m */; }; + 4B32F2041EF003E40066445B /* ThirdViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F2061EF003E40066445B /* ThirdViewController.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -43,6 +46,14 @@ 4B32F1EB1EEFF38D0066445B /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 4B32F1F51EEFF4340066445B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/SecondViewController.strings; sourceTree = ""; }; 4B32F1F71EEFF4360066445B /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/SecondViewController.strings"; sourceTree = ""; }; + 4B32F1FB1EF000220066445B /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/InfoPlist.strings; sourceTree = ""; }; + 4B32F1FD1EF000240066445B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 4B32F1FE1EF000250066445B /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/InfoPlist.strings"; sourceTree = ""; }; + 4B32F1FF1EF002D90066445B /* ThirdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThirdViewController.h; sourceTree = ""; }; + 4B32F2001EF002D90066445B /* ThirdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewController.m; sourceTree = ""; }; + 4B32F2051EF003E40066445B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ThirdViewController.xib; sourceTree = ""; }; + 4B32F2081EF003E50066445B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/ThirdViewController.strings; sourceTree = ""; }; + 4B32F20A1EF003E60066445B /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/ThirdViewController.strings"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -83,6 +94,9 @@ 4B32F1CC1EEFE7D90066445B /* SecondViewController.h */, 4B32F1CD1EEFE7D90066445B /* SecondViewController.m */, 4B32F1DA1EEFE9850066445B /* SecondViewController.xib */, + 4B32F1FF1EF002D90066445B /* ThirdViewController.h */, + 4B32F2001EF002D90066445B /* ThirdViewController.m */, + 4B32F2061EF003E40066445B /* ThirdViewController.xib */, 4B32F1C21EEFDEBE0066445B /* Class */, 4B32F1B71EEFDE840066445B /* Assets.xcassets */, 4B32F1B91EEFDE840066445B /* LaunchScreen.storyboard */, @@ -97,6 +111,7 @@ children = ( 4B32F1AC1EEFDE840066445B /* main.m */, 4B32F1E91EEFF38C0066445B /* Localizable.strings */, + 4B32F1FC1EF000220066445B /* InfoPlist.strings */, ); name = "Supporting Files"; sourceTree = ""; @@ -141,6 +156,7 @@ TargetAttributes = { 4B32F1A71EEFDE840066445B = { CreatedOnToolsVersion = 8.3.1; + DevelopmentTeam = YP3GK894M5; ProvisioningStyle = Automatic; }; }; @@ -169,7 +185,9 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4B32F2041EF003E40066445B /* ThirdViewController.xib in Resources */, 4B32F1E71EEFF38C0066445B /* Localizable.strings in Resources */, + 4B32F1FA1EF000220066445B /* InfoPlist.strings in Resources */, 4B32F1D81EEFE9850066445B /* SecondViewController.xib in Resources */, 4B32F1BB1EEFDE840066445B /* LaunchScreen.storyboard in Resources */, 4B32F1D11EEFE8A40066445B /* FirstViewController.xib in Resources */, @@ -186,6 +204,7 @@ files = ( 4B32F1CF1EEFE7DA0066445B /* SecondViewController.m in Sources */, 4B32F1C51EEFDEF40066445B /* NSBundle+AppLanguageSwitch.m in Sources */, + 4B32F2021EF002D90066445B /* ThirdViewController.m in Sources */, 4B32F1B01EEFDE840066445B /* AppDelegate.m in Sources */, 4B32F1AD1EEFDE840066445B /* main.m in Sources */, 4B32F1CA1EEFE7C10066445B /* FirstViewController.m in Sources */, @@ -234,6 +253,26 @@ name = Localizable.strings; sourceTree = ""; }; + 4B32F1FC1EF000220066445B /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 4B32F1FB1EF000220066445B /* Base */, + 4B32F1FD1EF000240066445B /* en */, + 4B32F1FE1EF000250066445B /* zh-Hans */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + 4B32F2061EF003E40066445B /* ThirdViewController.xib */ = { + isa = PBXVariantGroup; + children = ( + 4B32F2051EF003E40066445B /* Base */, + 4B32F2081EF003E50066445B /* en */, + 4B32F20A1EF003E60066445B /* zh-Hans */, + ); + name = ThirdViewController.xib; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -335,6 +374,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = YP3GK894M5; INFOPLIST_FILE = iOSAppLanguageSwitchDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -347,6 +387,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = YP3GK894M5; INFOPLIST_FILE = iOSAppLanguageSwitchDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/zengqingfu.xcuserdatad/UserInterfaceState.xcuserstate b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/zengqingfu.xcuserdatad/UserInterfaceState.xcuserstate index 13fd820..7122a01 100644 Binary files a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/zengqingfu.xcuserdatad/UserInterfaceState.xcuserstate and b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo.xcodeproj/project.xcworkspace/xcuserdata/zengqingfu.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Base.lproj/InfoPlist.strings b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Base.lproj/InfoPlist.strings new file mode 100644 index 0000000..b7fdf33 --- /dev/null +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Base.lproj/InfoPlist.strings @@ -0,0 +1,8 @@ +/* + InfoPlist.strings + iOSAppLanguageSwitchDemo + + Created by zengqingfu on 2017/6/13. + Copyright © 2017年 zengqingfu. All rights reserved. +*/ +"CFBundleDisplayName" = "语言切换"; diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Base.lproj/ThirdViewController.xib b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Base.lproj/ThirdViewController.xib new file mode 100644 index 0000000..f978fdf --- /dev/null +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Base.lproj/ThirdViewController.xib @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Class/NSBundle+AppLanguageSwitch.h b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Class/NSBundle+AppLanguageSwitch.h index 6889185..dcf30c6 100644 --- a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Class/NSBundle+AppLanguageSwitch.h +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Class/NSBundle+AppLanguageSwitch.h @@ -9,6 +9,8 @@ #import //语言改变通知 FOUNDATION_EXPORT NSString * const ZZAppLanguageDidChangeNotification; + + @interface NSBundle (AppLanguageSwitch) /** diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/SecondViewController.m b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/SecondViewController.m index 959ba5c..cae23be 100644 --- a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/SecondViewController.m +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/SecondViewController.m @@ -8,25 +8,43 @@ #import "SecondViewController.h" #import "NSBundle+AppLanguageSwitch.h" +#import "ThirdViewController.h" @interface SecondViewController () @end @implementation SecondViewController - +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view from its nib. + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageChange:) name:ZZAppLanguageDidChangeNotification object:nil]; } + + + +- (void)languageChange:(id)sender { + if (self.isViewLoaded && !self.view.window) { + //这里置为nil,当视图再次显示的时候会重新走viewDidLoad方法 + self.view = nil; + } +} + - (IBAction)closeAction:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } - (IBAction)setupChineseAction:(id)sender { - [NSBundle setCusLanguage:@"zh-Hans"]; + [self showHUDCompletion:^{ + [NSBundle setCusLanguage:@"zh-Hans"]; + }]; } - (IBAction)setupEnglishAction:(id)sender { - [NSBundle setCusLanguage:@"en"]; + [self showHUDCompletion:^{ + [NSBundle setCusLanguage:@"en"]; + }]; + } - (IBAction)currentLanguage:(id)sender { @@ -34,7 +52,11 @@ NSLog(@"当前语言是=%@", currLanguage); } - (IBAction)restoreLanguageAction:(id)sender { - [NSBundle restoreSysLanguage]; + + [self showHUDCompletion:^{ + [NSBundle restoreSysLanguage]; + }]; + } - (IBAction)strTestAction:(id)sender { @@ -42,6 +64,11 @@ NSLog(@"测试字符的结果是=%@", tes); } +- (void)showHUDCompletion:(void (^ __nullable)(void))completion { + ThirdViewController *vc = [[ThirdViewController alloc] init]; + [self presentViewController:vc animated:NO completion:completion]; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/ThirdViewController.h b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/ThirdViewController.h new file mode 100644 index 0000000..569e076 --- /dev/null +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/ThirdViewController.h @@ -0,0 +1,13 @@ +// +// ThirdViewController.h +// iOSAppLanguageSwitchDemo +// +// Created by zengqingfu on 2017/6/13. +// Copyright © 2017年 zengqingfu. All rights reserved. +// + +#import + +@interface ThirdViewController : UIViewController + +@end diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/ThirdViewController.m b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/ThirdViewController.m new file mode 100644 index 0000000..28ed2a6 --- /dev/null +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/ThirdViewController.m @@ -0,0 +1,44 @@ +// +// ThirdViewController.m +// iOSAppLanguageSwitchDemo +// +// Created by zengqingfu on 2017/6/13. +// Copyright © 2017年 zengqingfu. All rights reserved. +// + +#import "ThirdViewController.h" + +@interface ThirdViewController () + +@end + +@implementation ThirdViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. +} + +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self dismissViewControllerAnimated:NO completion:nil]; + }); +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/en.lproj/InfoPlist.strings b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..649d73f --- /dev/null +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/en.lproj/InfoPlist.strings @@ -0,0 +1,8 @@ +/* + InfoPlist.strings + iOSAppLanguageSwitchDemo + + Created by zengqingfu on 2017/6/13. + Copyright © 2017年 zengqingfu. All rights reserved. +*/ +"CFBundleDisplayName" = "Lan Switch"; diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/en.lproj/ThirdViewController.strings b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/en.lproj/ThirdViewController.strings new file mode 100644 index 0000000..f898e75 --- /dev/null +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/en.lproj/ThirdViewController.strings @@ -0,0 +1,3 @@ + +/* Class = "UILabel"; text = "正在设置语言..."; ObjectID = "yTu-Le-1xE"; */ +"yTu-Le-1xE.text" = "setting Language"; diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/zh-Hans.lproj/InfoPlist.strings b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/zh-Hans.lproj/InfoPlist.strings new file mode 100644 index 0000000..b7fdf33 --- /dev/null +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/zh-Hans.lproj/InfoPlist.strings @@ -0,0 +1,8 @@ +/* + InfoPlist.strings + iOSAppLanguageSwitchDemo + + Created by zengqingfu on 2017/6/13. + Copyright © 2017年 zengqingfu. All rights reserved. +*/ +"CFBundleDisplayName" = "语言切换"; diff --git a/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/zh-Hans.lproj/ThirdViewController.strings b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/zh-Hans.lproj/ThirdViewController.strings new file mode 100644 index 0000000..4f22d8d --- /dev/null +++ b/iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/zh-Hans.lproj/ThirdViewController.strings @@ -0,0 +1,3 @@ + +/* Class = "UILabel"; text = "正在设置语言..."; ObjectID = "yTu-Le-1xE"; */ +"yTu-Le-1xE.text" = "正在设置语言...";