Commit 0e5b5ae4 authored by 汪洋's avatar 汪洋

root view controller不支持旋转;可以通过h5为导航栏设置right button

parent 85c3ac62
......@@ -10,6 +10,7 @@
#import "UIViewController+PushType.h"
#import "GMPresentAnimation.h"
@import GMKit;
@interface GMNavigationController ()<UINavigationControllerDelegate>
@end
......@@ -41,4 +42,16 @@
return nil;
}
// 依据supportedInterfaceOrientations文档,控制旋转的代码需要写在root view controller,或者全屏的presenting controller
// app的root view controller就是这个GMNavigationController,所以相关控制代码在这里。
- (BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
@end
......@@ -46,6 +46,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy, nullable) NSString *rightTitle;
@property (nonatomic, copy, nullable) NSString *nearRightTitle;
/**
由h5 pagedata中传递过来的right_button
*/
@property (nonatomic, copy, nullable) NSString *nearRightIconURL;
@property (nonatomic, copy, nullable) NSString *rightIconURL;
/// 默认显示阴影(严格来说是一条线,并不是阴影)
- (void)showShadow:(BOOL)show;
- (void)hideAllItems;
......
......@@ -45,6 +45,7 @@
make.height.offset(1/[UIScreen mainScreen].scale);
}];
_itemView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, [UIScreen mainScreen].bounds.size.width, 44)];
_itemView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
CGFloat titleW = [UIScreen mainScreen].bounds.size.width - 80;
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, titleW, 44)];
_titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
......@@ -203,6 +204,35 @@
[_nearRightButton setTitle:_nearRightTitle forState:UIControlStateNormal];
[self layoutTitle];
}
- (void)setNearRightIconURL:(NSString *)nearRightIconURL {
_nearRightIconURL = nearRightIconURL;
_nearRightButton.hidden = NO;
[[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:_nearRightIconURL] options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image) {
NSData *imageData = UIImagePNGRepresentation(image);
UIImage *scaledImage = [UIImage imageWithData:imageData scale:[UIScreen mainScreen].scale];
[_nearRightButton setImage:scaledImage forState:UIControlStateNormal];
}
}];
[self layoutTitle];
}
- (void)setRightIconURL:(NSString *)rightIconURL {
_rightIconURL = rightIconURL;
_rightButton.hidden = NO;
[[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:rightIconURL] options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image) {
NSData *imageData = UIImagePNGRepresentation(image);
UIImage *scaledImage = [UIImage imageWithData:imageData scale:[UIScreen mainScreen].scale];
[_rightButton setImage:scaledImage forState:UIControlStateNormal];
}
}];
[self layoutTitle];
}
@end
@implementation OCNavigationBar (ViewConstant)
......
......@@ -122,6 +122,11 @@
- (void)addNavigationBar {
_navigationBar.delegate = self;
[self.view addSubview:_navigationBar];
[_navigationBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.right.mas_equalTo(0);
make.height.mas_equalTo(OCNavigationBar.barHeight);
}];
}
- (void)hideLeftButtonForRootController {
......@@ -168,5 +173,4 @@
}
- (void)emptyViewDidClickReload {}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment