zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
//
//  PBOpenDrawController.m
//  IphoneBIMe
//
//  Created by zjf on 2019/1/16.
//  Copyright © 2019 ProBIM. All rights reserved.
//
 
#import "PBOpenDrawController.h"
#import "PBDrawingsModel.h"
#import "PBModelsModel.h"
#import "PBDrawingsInfoModel.h"
#import "PBIssueAddModel.h"
#import "PBDrawingposModel.h"
#define positionImageVW 30
#define positionImageVH 30
 
@interface PBOpenDrawController ()<UIScrollViewDelegate>
@property (nonatomic,strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIImageView *imageV;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) UIView *redView;
@property (nonatomic, strong) UIImageView *positionImageV;
@end
 
@implementation PBOpenDrawController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNav];
    [self setupUI];
}
 
- (void)setNav {
    self.view.backgroundColor = [UIColor whiteColor];
    PBBackNavItem *backNav = [PBBackNavItem backNacItem];
    backNav.title = @" ";
    [backNav addTarget:self action:@selector(backNavAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithCustomView:backNav];
    self.navigationItem.leftBarButtonItem = backNavItem;
}
 
- (void)backNavAction {
    [self.navigationController popViewControllerAnimated:YES];
}
 
- (void)setupUI {
    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(self.view);
    }];
    
    self.imageV = [[UIImageView alloc] init];
    self.imageV.image = self.image;
    self.imageV.contentMode = UIViewContentModeScaleToFill;
    [self.scrollView addSubview:self.imageV];
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(self.scrollView);
    }];
    CGFloat x = [self.drawingposModel.PosX floatValue];
    CGFloat y = [self.drawingposModel.PosY floatValue];
    self.redView.frame = CGRectMake(x, y, 1, 1);
    [self.imageV addSubview:self.redView];
    
    
    self.scrollView.contentSize = self.image.size;
    NSInteger imageW = CGImageGetWidth(self.image.CGImage);
    NSInteger width = self.view.bounds.size.width;
    CGFloat scale = (CGFloat)width / (CGFloat)imageW;
    self.scrollView.maximumZoomScale = 2;
    self.scrollView.minimumZoomScale = scale;
    [self.scrollView setZoomScale:scale animated:NO];
    
    CGPoint point = [self.redView convertPoint:CGPointMake(0, 0) toView:self.view];
    self.positionImageV.frame = CGRectMake(point.x - (positionImageVW / 2), point.y - positionImageVH, positionImageVW, positionImageVH);
    [self.view addSubview:self.positionImageV];
}
 
- (void)setDrawingsInfoModel:(PBDrawingsInfoModel *)drawingsInfoModel {
    _drawingsInfoModel = drawingsInfoModel;
    self.title = drawingsInfoModel.name;
    self.image = [NSString imageDecoding:self.drawingsInfoModel.imagebase64];
}
- (void)setDrawingposModel:(PBDrawingposModel *)drawingposModel {
    _drawingposModel = drawingposModel;
}
#pragma mark - UIScrollViewDelegate
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.imageV;
}
 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [self changegreenView];
}
 
- (UIView *)redView {
    if (_redView == nil) {
        _redView = [[UIView alloc] init];
        _redView.backgroundColor = [UIColor redColor];
    }
    return _redView;
}
- (UIImageView *)positionImageV {
    if (_positionImageV == nil) {
        _positionImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"location"]];
    }
    return _positionImageV;
}
 
- (void)changegreenView {
    CGPoint point = [self.redView convertPoint:CGPointMake(0, 0) toView:self.view];
    CGRect frame = CGRectMake(point.x - (positionImageVW / 2), point.y - positionImageVH, positionImageVW, positionImageVH);
    self.positionImageV.frame = frame;
    NSLog(@"self.views位置-----------------------%@",NSStringFromCGPoint(point));
}
 
/*
#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