Skip to content

Commit 49c0d4f

Browse files
committed
代码横屏预览
1 parent bd6e761 commit 49c0d4f

9 files changed

Lines changed: 115 additions & 25 deletions

File tree

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
4E6BA2E61A1EE6AF005FD721 /* UIProgressView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6BA2D11A1EE6AF005FD721 /* UIProgressView+AFNetworking.m */; };
7474
4E6BA2E71A1EE6AF005FD721 /* UIRefreshControl+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6BA2D31A1EE6AF005FD721 /* UIRefreshControl+AFNetworking.m */; };
7575
4E6BA2E81A1EE6AF005FD721 /* UIWebView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6BA2D51A1EE6AF005FD721 /* UIWebView+AFNetworking.m */; };
76+
4E6C41191A834EA90098DC17 /* BaseNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6C41181A834EA90098DC17 /* BaseNavigationController.m */; };
7677
4E6D71891A75F00E005AD988 /* YLGIFImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6D71861A75F00E005AD988 /* YLGIFImage.m */; };
7778
4E6D718A1A75F00E005AD988 /* YLImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E6D71881A75F00E005AD988 /* YLImageView.m */; };
7879
4E6D718D1A762879005AD988 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4E6D718B1A762879005AD988 /* [email protected] */; };
@@ -644,6 +645,8 @@
644645
4E6BA2D31A1EE6AF005FD721 /* UIRefreshControl+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIRefreshControl+AFNetworking.m"; sourceTree = "<group>"; };
645646
4E6BA2D41A1EE6AF005FD721 /* UIWebView+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIWebView+AFNetworking.h"; sourceTree = "<group>"; };
646647
4E6BA2D51A1EE6AF005FD721 /* UIWebView+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIWebView+AFNetworking.m"; sourceTree = "<group>"; };
648+
4E6C41171A834EA90098DC17 /* BaseNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseNavigationController.h; sourceTree = "<group>"; };
649+
4E6C41181A834EA90098DC17 /* BaseNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseNavigationController.m; sourceTree = "<group>"; };
647650
4E6D71851A75F00E005AD988 /* YLGIFImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YLGIFImage.h; sourceTree = "<group>"; };
648651
4E6D71861A75F00E005AD988 /* YLGIFImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YLGIFImage.m; sourceTree = "<group>"; };
649652
4E6D71871A75F00E005AD988 /* YLImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YLImageView.h; sourceTree = "<group>"; };
@@ -2197,6 +2200,8 @@
21972200
children = (
21982201
8EA6CF3319E240C40076D59C /* BaseViewController.h */,
21992202
8EA6CF3419E240C40076D59C /* BaseViewController.m */,
2203+
4E6C41171A834EA90098DC17 /* BaseNavigationController.h */,
2204+
4E6C41181A834EA90098DC17 /* BaseNavigationController.m */,
22002205
8EA6CF3D19E240C40076D59C /* RootTabViewController.h */,
22012206
8EA6CF3E19E240C40076D59C /* RootTabViewController.m */,
22022207
8EA6CF3519E240C40076D59C /* Me_RootViewController.h */,
@@ -3269,6 +3274,7 @@
32693274
4E8AF7861A53D69F00CDC3AE /* StartImagesManager.m in Sources */,
32703275
8EA6D13419E240C40076D59C /* ProjectMemberListViewController.m in Sources */,
32713276
8EF643CC19FF7E2900F7EEB0 /* TweetCommentCell.m in Sources */,
3277+
4E6C41191A834EA90098DC17 /* BaseNavigationController.m in Sources */,
32723278
8EA6D23A19E240C40076D59C /* ProjectTopicListView.m in Sources */,
32733279
4E6BA2D91A1EE6AF005FD721 /* AFURLConnectionOperation.m in Sources */,
32743280
8EA6D1BB19E240C40076D59C /* ProjectTopic.m in Sources */,

Coding_iOS/Coding_iOS-Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
<key>UISupportedInterfaceOrientations</key>
4747
<array>
4848
<string>UIInterfaceOrientationPortrait</string>
49+
<string>UIInterfaceOrientationLandscapeLeft</string>
50+
<string>UIInterfaceOrientationLandscapeRight</string>
4951
</array>
5052
<key>UIViewControllerBasedStatusBarAppearance</key>
5153
<false/>

Coding_iOS/Controllers/CodeViewController.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ - (void)didReceiveMemoryWarning {
5656
// Dispose of any resources that can be recreated.
5757
}
5858

59+
#pragma mark - Orientations
60+
- (BOOL)shouldAutorotate {
61+
return YES;
62+
}
63+
64+
- (NSUInteger)supportedInterfaceOrientations{
65+
return UIInterfaceOrientationMaskAllButUpsideDown;
66+
}
67+
5968
#pragma mark Request
6069

6170
- (void)sendRequest{
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// BaseNavigationController.h
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/2/5.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface BaseNavigationController : UINavigationController
12+
13+
@end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// BaseNavigationController.m
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 15/2/5.
6+
// Copyright (c) 2015年 Coding. All rights reserved.
7+
//
8+
9+
#import "BaseNavigationController.h"
10+
11+
@implementation BaseNavigationController
12+
13+
- (BOOL)shouldAutorotate{
14+
return [self.visibleViewController shouldAutorotate];
15+
}
16+
17+
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
18+
return [self.visibleViewController preferredInterfaceOrientationForPresentation];
19+
}
20+
21+
- (NSUInteger)supportedInterfaceOrientations {
22+
return [self.visibleViewController supportedInterfaceOrientations];
23+
}
24+
25+
@end

Coding_iOS/Controllers/RootControllers/BaseViewController.m

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ - (void)viewWillAppear:(BOOL)animated
3434
{
3535
[super viewWillAppear:animated];
3636
[MobClick beginLogPageView:[NSString stringWithUTF8String:object_getClassName(self)]];
37+
38+
if (self.interfaceOrientation != UIInterfaceOrientationPortrait
39+
&&![self isMemberOfClass:NSClassFromString(@"CodeViewController")]) {
40+
[self forceChangeToOrientation:UIInterfaceOrientationPortrait];
41+
}
3742
}
3843
- (void)viewWillDisappear:(BOOL)animated
3944
{
@@ -44,15 +49,39 @@ - (void)viewWillDisappear:(BOOL)animated
4449

4550
- (void)viewDidLoad{
4651
[super viewDidLoad];
47-
4852
self.view.backgroundColor = kColorTableBG;
53+
}
4954

55+
- (void)loadView{
56+
[super loadView];
57+
58+
if (self.interfaceOrientation != UIInterfaceOrientationPortrait
59+
&&![self isMemberOfClass:NSClassFromString(@"CodeViewController")]) {
60+
[self forceChangeToOrientation:UIInterfaceOrientationPortrait];
61+
}
5062
}
5163

5264
- (void)tabBarItemClicked{
5365
NSLog(@"\ntabBarItemClicked : %@", NSStringFromClass([self class]));
5466
}
5567

68+
#pragma mark - Orientations
69+
- (BOOL)shouldAutorotate{
70+
return UIInterfaceOrientationIsLandscape(self.interfaceOrientation);
71+
}
72+
73+
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
74+
return UIInterfaceOrientationPortrait;
75+
}
76+
77+
- (NSUInteger)supportedInterfaceOrientations {
78+
return UIInterfaceOrientationMaskPortrait;
79+
}
80+
81+
- (void)forceChangeToOrientation:(UIInterfaceOrientation)interfaceOrientation{
82+
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:interfaceOrientation] forKey:@"orientation"];
83+
}
84+
5685
#pragma mark Notification
5786
+ (void)handleNotificationInfo:(NSDictionary *)userInfo{
5887
//标记为已读

Coding_iOS/Controllers/RootControllers/RootTabViewController.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import "Message_RootViewController.h"
1515
#import "RDVTabBarItem.h"
1616
#import "UnReadManager.h"
17+
#import "BaseNavigationController.h"
1718

1819
@interface RootTabViewController ()
1920

@@ -57,19 +58,19 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
5758
#pragma mark Private_M
5859
- (void)setupViewControllers {
5960
Project_RootViewController *project = [[Project_RootViewController alloc] init];
60-
UINavigationController *nav_project = [[UINavigationController alloc] initWithRootViewController:project];
61+
UINavigationController *nav_project = [[BaseNavigationController alloc] initWithRootViewController:project];
6162

6263
MyTask_RootViewController *mytask = [[MyTask_RootViewController alloc] init];
63-
UINavigationController *nav_mytask = [[UINavigationController alloc] initWithRootViewController:mytask];
64+
UINavigationController *nav_mytask = [[BaseNavigationController alloc] initWithRootViewController:mytask];
6465

6566
Tweet_RootViewController *tweet = [[Tweet_RootViewController alloc] init];
66-
UINavigationController *nav_tweet = [[UINavigationController alloc] initWithRootViewController:tweet];
67+
UINavigationController *nav_tweet = [[BaseNavigationController alloc] initWithRootViewController:tweet];
6768

6869
Message_RootViewController *message = [[Message_RootViewController alloc] init];
69-
UINavigationController *nav_message = [[UINavigationController alloc] initWithRootViewController:message];
70+
UINavigationController *nav_message = [[BaseNavigationController alloc] initWithRootViewController:message];
7071

7172
Me_RootViewController *me = [[Me_RootViewController alloc] init];
72-
UINavigationController *nav_me = [[UINavigationController alloc] initWithRootViewController:me];
73+
UINavigationController *nav_me = [[BaseNavigationController alloc] initWithRootViewController:me];
7374

7475
[self setViewControllers:@[nav_project, nav_mytask, nav_tweet, nav_message, nav_me]];
7576

Coding_iOS/Vendor/RDVTabBarController/RDVTabBarController.m

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,34 @@ - (void)viewWillAppear:(BOOL)animated {
5858
[self setTabBarHidden:NO animated:NO];
5959
}
6060

61-
- (NSUInteger)supportedInterfaceOrientations {
62-
UIInterfaceOrientationMask orientationMask = UIInterfaceOrientationMaskAll;
63-
for (UIViewController *viewController in [self viewControllers]) {
64-
if (![viewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
65-
return UIInterfaceOrientationMaskPortrait;
61+
- (BOOL)shouldAutorotate{
62+
if (self.viewControllers.count > _selectedIndex) {
63+
UIViewController *viewController = self.viewControllers[_selectedIndex];
64+
if ([viewController respondsToSelector:@selector(shouldAutorotate)]) {
65+
return [viewController shouldAutorotate];
6666
}
67-
68-
UIInterfaceOrientationMask supportedOrientations = [viewController supportedInterfaceOrientations];
69-
70-
if (orientationMask > supportedOrientations) {
71-
orientationMask = supportedOrientations;
67+
}
68+
return YES;
69+
}
70+
71+
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
72+
if (self.viewControllers.count > _selectedIndex) {
73+
UIViewController *viewController = self.viewControllers[_selectedIndex];
74+
if ([viewController respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) {
75+
return [viewController preferredInterfaceOrientationForPresentation];
7276
}
7377
}
74-
75-
return orientationMask;
78+
return UIInterfaceOrientationPortrait;
7679
}
7780

78-
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
79-
for (UIViewController *viewCotroller in [self viewControllers]) {
80-
if (![viewCotroller respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)] ||
81-
![viewCotroller shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]) {
82-
return NO;
81+
- (NSUInteger)supportedInterfaceOrientations {
82+
if (self.viewControllers.count > _selectedIndex) {
83+
UIViewController *viewController = self.viewControllers[_selectedIndex];
84+
if ([viewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
85+
return [viewController supportedInterfaceOrientations];
8386
}
8487
}
85-
return YES;
88+
return UIInterfaceOrientationMaskPortrait;
8689
}
8790

8891
#pragma mark - Methods

Coding_iOS/Vendor/SVWebViewController/SVWebViewController.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
//
77
// https://github.com/samvermette/SVWebViewController
88

9-
@interface SVWebViewController : UIViewController
9+
#import "BaseViewController.h"
10+
11+
@interface SVWebViewController : BaseViewController
1012

1113
- (instancetype)initWithAddress:(NSString*)urlString;
1214
- (instancetype)initWithURL:(NSURL*)URL;

0 commit comments

Comments
 (0)