developer
2023-10-23 5d70d9a1849bac7a9eb3f24931d6a8987dd7b6e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
//  BaseViewController.m
//  BuWanVideo2.0
//
//  Created by apple on 2018/3/13.
//  Copyright © 2018年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "BaseViewController.h"
#import "LookNoteController.h"
#import "searchViewController.h"
@interface BaseViewController ()
@property (nonatomic , strong) NSMutableArray *dataHot;//热门搜索
@property (nonatomic , strong) UITextField *searchText;//搜索框
 
@end
 
@implementation BaseViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
 
}
- (void)viewWillAppear:(BOOL)animated{
//    self.navigationController.navigationBar.translucent = NO;
    self.dataHot = @[].mutableCopy;
    [self getHotSearch];
    [self loadNavigationbar];
 
}
-(void)loadNavigationbar{
    //去掉titlie
    UIView *tview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0.01, 0.01)];
    self.navigationItem.titleView = tview;
    
    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    //    创建一个高20的假状态栏
    UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, KScreenW, 20)];
//    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
//    statusBarView.frame = statusBarFrame;
    if (KIsiPhoneX) {
        statusBarView.frame = CGRectMake(0, -44, KScreenW, 44);
    }
    NSLog(@"%f == %f  \n  %f === %f",KScreenH,KScreenW,[[UIScreen mainScreen] currentMode].size.height,[[UIScreen mainScreen] currentMode].size.width);
    //    设置颜色
    //statusBarView.backgroundColor = kGlobalMainColor;
    //[self.navigationController.navigationBar setBackgroundColor:kGlobalMainColor];
 
    [self.navigationController.navigationBar addSubview:statusBarView];
    //搜索
    UIView *seachView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,  KScreenW / 5 * 4, 30)];
    self.searchText = [[UITextField alloc]initWithFrame:CGRectMake(0, 0,seachView.frame.size.width, seachView.frame.size.height)];
    self.searchText.backgroundColor = [UIColor colorWithWhite:0.7 alpha:0.2];
    self.searchText.layer.cornerRadius = self.searchText.frame.size.height / 2;
    self.searchText.textColor = [UIColor whiteColor];
    self.searchText.font = [UIFont systemFontOfSize:14];
    UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 45, 25)];
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 3, 19, 19)];
    imageview.image = [UIImage imageNamed:@"搜索"];
    [leftView addSubview:imageview];
    self.searchText.leftView = leftView;
    self.searchText.leftViewMode = UITextFieldViewModeAlways;
    UIButton *textButton = [UIButton buttonWithType:UIButtonTypeCustom];
    textButton.frame = CGRectMake(0, 0,seachView.frame.size.width, seachView.frame.size.height);
    [textButton addTarget:self action:@selector(JumpToSearchView) forControlEvents:UIControlEventTouchUpInside];
    [seachView addSubview:self.searchText];
    
    [seachView addSubview:textButton];
    UIBarButtonItem *searchItem = [[UIBarButtonItem alloc] initWithCustomView:seachView];
 
    //观看记录
    UIButton *recordBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
    [recordBtn setImage:[UIImage imageNamed:@"历史记录"] forState:UIControlStateNormal];
    [recordBtn addTarget:self action:@selector(JumpToRecordView) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *recordBarItem=[[UIBarButtonItem alloc] initWithCustomView:recordBtn];
    //    //下载
    //    UIButton *downLoadBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
    //    downLoadBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 4);
    //    [downLoadBtn setImage:[UIImage imageNamed:@"缓存"] forState:UIControlStateNormal];
    //    [downLoadBtn addTarget:self action:@selector(JumpToDownloadView) forControlEvents:UIControlEventTouchUpInside];
    //    UIBarButtonItem *downLoadBarItem=[[UIBarButtonItem alloc] initWithCustomView:downLoadBtn];
    //搜索
//    UIButton *SearchBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
//    [SearchBtn setImage:[UIImage imageNamed:@"搜索"] forState:UIControlStateNormal];
//    [SearchBtn addTarget:self action:@selector(JumpToSearchView) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *SearchBarItem=[[UIBarButtonItem alloc] initWithCustomView:SearchBtn];
    //空白间距
    UILabel *WhiteLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 8, 10)];
    WhiteLabel.backgroundColor=[UIColor clearColor];
    UIBarButtonItem *WhiteBarItem=[[UIBarButtonItem alloc] initWithCustomView:WhiteLabel];
    
    UILabel *WhiteLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 10)];
    WhiteLabel1.backgroundColor=[UIColor clearColor];
    UIBarButtonItem *WhiteBarItem1=[[UIBarButtonItem alloc] initWithCustomView:WhiteLabel1];
    //添加 观看记录/下载/搜索 到导航栏
    self.navigationItem.rightBarButtonItems=[[NSArray alloc] initWithObjects:recordBarItem,searchItem,WhiteBarItem,nil];
}
/**
 *  跳转到历史记录
 */
-(void)JumpToRecordView{
    LookNoteController *LookNoteLookNoteVC=[[LookNoteController alloc] init];
    [LookNoteLookNoteVC setHidesBottomBarWhenPushed:YES];
 
    [self.navigationController pushViewController:LookNoteLookNoteVC animated:YES];
}
 
/**
 *  跳转到搜索
 */
-(void)JumpToSearchView{
    searchViewController *searchVC=[[searchViewController alloc] init];
    [searchVC setHidesBottomBarWhenPushed:YES];
 
    [self.navigationController pushViewController:searchVC animated:YES];
}
 
- (void)getHotSearch{
    [[YTHNetInterface startInterface] getHotSerachWithUid:[YTHsharedManger startManger].Uid withSystem:@"1" withblock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSDictionary *dic = (NSDictionary *)result;
            if (!_dataHot) {
                _dataHot = [[NSMutableArray alloc] initWithCapacity:0];
            }
            [_dataHot removeAllObjects];
            NSArray *ar = [[dic objectForKey:@"Data"] objectForKey:@"data"];
            for (int i =0; i<ar.count; i++) {
                [_dataHot addObject:[ar objectAtIndex:i]];
            }
            NSLog(@"////%@'''''",_dataHot);
            if ([YTHsharedManger startManger].searchTitle.length == 0) {
                NSInteger rand = arc4random()%self.dataHot.count ;
                self.searchText.text = self.dataHot[rand];
                [YTHsharedManger startManger].searchTitle = self.searchText.text;
            }else{
                self.searchText.text = [YTHsharedManger startManger].searchTitle;
            }
            //刷新热门搜索
        }else{
            //显示网络连接失败
        }
    }];
}
 
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
 
@end