ifish/Ifish/controllers/IfishTabControllers/我的/mineControllers/InfoByImageViewController.m

445 lines
14 KiB
Objective-C

//
// InfoByImageViewController.m
// Ifish
//
// Created by 祝发冬 on 2020/6/20.
// Copyright © 2020 lianlian. All rights reserved.
//
#import "InfoByImageViewController.h"
@interface InstructionCell : UITableViewCell
@property (nonatomic, strong) NSDictionary *model;
@property (nonatomic, strong) UIImageView *icon;
@end
@implementation InstructionCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectZero];
[self.contentView addSubview:imageView];
imageView.contentMode=UIViewContentModeScaleToFill;
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.bottom.mas_equalTo(0);
make.right.mas_equalTo(0); }];
self.icon=imageView;
}
return self;
}
- (void)setModel:(NSDictionary *)model
{
_model=model;
UIImage*image=[UIImage imageNamed:model[@"image"]];
if (image)
{
self.icon.image=image;
}
else
{
self.icon.image=nil;
}
}
@end
@interface InfoByImageViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, assign) CGFloat rowHeight;
@end
@implementation InfoByImageViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.scrollView=[[UIScrollView alloc]initWithFrame:CGRectZero];
//self.scrollView.clipsToBounds=YES;
self.imageView=[[UIImageView alloc]initWithFrame:CGRectZero];
// self.imageView.contentMode=UIViewContentModeCenter;
[self.scrollView addSubview:self.imageView];
//self.scrollView.scrollEnabled=NO;
[self.view addSubview:self.scrollView];
self.imageView.userInteractionEnabled=YES;
[ self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.bottom.mas_equalTo(0);
make.right.mas_equalTo(0);
}];
CGFloat imageHeight=kScreenHeight-TOP_HEIGHT;
CGFloat imageWidth=kScreenWidth;
CGFloat ratio=imageWidth/imageHeight;
if (self.image)
{
ratio=self.image.size.width/self.image.size.height;
}
imageHeight=imageWidth/ratio;
self.scrollView.contentSize=CGSizeMake(imageWidth, imageHeight);
[ self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.scrollView);
make.top.mas_equalTo(self.scrollView);
make.height.mas_equalTo(imageHeight);
make.width.mas_equalTo(imageWidth);
// make.right.mas_equalTo(self.view);
}];
if (self.image)
{
self.imageView.image=self.image;
}
if (self.title)
{
self.titleString=self.title;
}
if ([self.type isEqualToString:@"service"])
{
UIButton*xuanduo=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:xuanduo];
[xuanduo mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.height.mas_equalTo(imageHeight/12);
make.right.mas_equalTo(0);
}];
xuanduo.tag=1;
xuanduo.backgroundColor=[UIColor clearColor];
[xuanduo addTarget:self action:@selector(service:) forControlEvents:UIControlEventTouchUpInside];
UIButton*reuxin=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:reuxin];
[reuxin mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(4*imageHeight/12);
make.height.mas_equalTo(imageHeight/12);
make.right.mas_equalTo(0);
}];
reuxin.tag=2;
reuxin.backgroundColor=[UIColor clearColor];
[reuxin addTarget:self action:@selector(service:) forControlEvents:UIControlEventTouchUpInside];
UIButton*songnuo=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:songnuo];
[songnuo mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(8*imageHeight/12);
make.height.mas_equalTo(imageHeight/12);
make.right.mas_equalTo(0);
}];
songnuo.tag=3;
songnuo.backgroundColor=[UIColor clearColor];
[songnuo addTarget:self action:@selector(service:) forControlEvents:UIControlEventTouchUpInside];
}
else if ([self.type isEqualToString:@"instruction"])//详细说明书
{
// [self getTableData];
// [self creatTab];
// return;
NSInteger count =9;
CGFloat itemHeight=imageHeight/count;
for (int i=0; i<count; i++)
{
UIButton*camera=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:camera];
[camera mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(i*itemHeight);
make.height.mas_equalTo(itemHeight);
make.right.mas_equalTo(0);
}];
camera.tag=i+1;
camera.backgroundColor=[UIColor clearColor];
[camera addTarget:self action:@selector(instruction:) forControlEvents:UIControlEventTouchUpInside];
}
return;
UIButton*camera=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:camera];
[camera mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.height.mas_equalTo(imageHeight/7);
make.right.mas_equalTo(0);
}];
camera.tag=1;
camera.backgroundColor=[UIColor clearColor];
[camera addTarget:self action:@selector(instruction:) forControlEvents:UIControlEventTouchUpInside];
UIButton*senven=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:senven];
[senven mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(imageHeight/7);
make.height.mas_equalTo(1*imageHeight/7);
make.right.mas_equalTo(0);
}];
senven.tag=2;
senven.backgroundColor=[UIColor clearColor];
[senven addTarget:self action:@selector(instruction:) forControlEvents:UIControlEventTouchUpInside];
UIButton*sw7=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:sw7];
[sw7 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(2*imageHeight/7);
make.height.mas_equalTo(1*imageHeight/7);
make.right.mas_equalTo(0);
}];
sw7.tag=3;
sw7.backgroundColor=[UIColor clearColor];
[sw7 addTarget:self action:@selector(instruction:) forControlEvents:UIControlEventTouchUpInside];
UIButton*sw10=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:sw10];
[sw10 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(3*imageHeight/7);
make.height.mas_equalTo(1*imageHeight/7);
make.right.mas_equalTo(0);
}];
sw10.tag=4;
sw10.backgroundColor=[UIColor clearColor];
[sw10 addTarget:self action:@selector(instruction:) forControlEvents:UIControlEventTouchUpInside];
UIButton*cw2=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:cw2];
[cw2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(4*imageHeight/7);
make.height.mas_equalTo(1*imageHeight/7);
make.right.mas_equalTo(0);
}];
cw2.tag=5;
cw2.backgroundColor=[UIColor clearColor];
[cw2 addTarget:self action:@selector(instruction:) forControlEvents:UIControlEventTouchUpInside];
UIButton*sw1_6=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:sw1_6];
[sw1_6 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(5*imageHeight/7);
make.height.mas_equalTo(1*imageHeight/7);
make.right.mas_equalTo(0);
}];
sw1_6.tag=6;
sw1_6.backgroundColor=[UIColor clearColor];
[sw1_6 addTarget:self action:@selector(instruction:) forControlEvents:UIControlEventTouchUpInside];
UIButton*hxwy01=[UIButton buttonWithType:UIButtonTypeSystem];
[self.imageView addSubview:hxwy01];
[hxwy01 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(6*imageHeight/7);
make.height.mas_equalTo(1*imageHeight/7);
make.right.mas_equalTo(0);
}];
hxwy01.tag=7;
hxwy01.backgroundColor=[UIColor clearColor];
[hxwy01 addTarget:self action:@selector(instruction:) forControlEvents:UIControlEventTouchUpInside];
}
}
-(void)getTableData{
NSArray*array=@[@{@"image":@"roleCa",@"title":@"常见失败原因",@"instructionImage":@"failreason"}];
self.dataArray=array;
}
-(void)creatTab{
self.automaticallyAdjustsScrollViewInsets = NO;
if (self.tableView==nil) {
UITableView*table=[[UITableView alloc]initWithFrame:CGRectMake(0,0, kScreenSize.width, kScreenSize.height) style:UITableViewStylePlain];
table.dataSource=self;
if (@available(iOS 15.0, *)) {
table.sectionHeaderTopPadding=0;
}
table.delegate=self;
table.separatorStyle=UITableViewCellSeparatorStyleNone;
self.tableView=table;
self.tableView.showsVerticalScrollIndicator=NO;
self.tableView.backgroundColor = TABLE_HEADER_COLOR;
[self.view addSubview:self.tableView];
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0,50, 0,0)];
[self.tableView setSeparatorColor:TABLE_SEPRETLINE_COLOR];
}
}
}
-(void)instruction:(UIButton*)button
{
self.hidesBottomBarWhenPushed = YES;
InfoByImageViewController*info=[[InfoByImageViewController alloc]init];
if (button.tag==1) {
info.title=@"常见失败原因";
info.image=[UIImage imageNamed:@"failreason"];
}
else if (button.tag==2) {
info.title=@"小7摄像头";
info.image=[UIImage imageNamed:@"cameraInfo"];
}
else if (button.tag==3) {
info.title=@"摇头摄像机";
info.image=[UIImage imageNamed:@"摇头机说明书"];
}
else if (button.tag==4) {
info.title=@"绚多SW7";
info.image=[UIImage imageNamed:@"SW7"];
}
else if (button.tag==5) {
info.title=@"绚多SW10";
info.image=[UIImage imageNamed:@"SW10"];
}
else if (button.tag==6) {
info.title=@"绚多CW2";
info.image=[UIImage imageNamed:@"CW2"];
}
else if (button.tag==7) {
info.title=@"绚多SW1/SW6/W6";
info.image=[UIImage imageNamed:@"sw1"];
}
else if (button.tag==8) {
info.title=@"睿芯HX-WY01";
info.image=[UIImage imageNamed:@"HX-WY01"];
}
else if (button.tag==9) {
info.title=@"松诺";
info.image=[UIImage imageNamed:@"songnuo"];
}
[self.navigationController pushViewController:info animated:YES];
}
-(void)service:(UIButton*)button
{
NSURL*url;
if (button.tag==1)
{
url=[NSURL URLWithString:@"tel://17321129273"];
}
else if (button.tag==2)
{
url=[NSURL URLWithString:@"tel://4000121101"];
}
else if (button.tag==3)
{
url=[NSURL URLWithString:@"tel://13392205468"];
}
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}else {
[[UIApplication sharedApplication] openURL:url];
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 124;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString*identiy=@"InstructionCell";
InstructionCell*cell=[tableView dequeueReusableCellWithIdentifier:identiy];
if (!cell)
{
cell=[[InstructionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identiy];
}
[cell setModel:self.dataArray[indexPath.row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
self.hidesBottomBarWhenPushed = YES;
InfoByImageViewController*info=[[InfoByImageViewController alloc]init];
NSDictionary*model=self.dataArray[indexPath.row];
info.title=model[@"title"];
info.image=[UIImage imageNamed:model[@"instructionImage"]];
[self.navigationController pushViewController:info animated:YES];
}
/*
#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