123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911 |
- //
- // PanoramaGuideView.m
- // LenzCameraNativeModuleForRN
- //
- // Created by 王昭威 on 2023/1/25.
- //
- #import "PanoramaGuideView.h"
- #import <YYText/NSAttributedString+YYText.h>
- #import <AVFoundation/AVFoundation.h>
- #import <YYText/YYLabel.h>
- #import <MetalKit/MetalKit.h>
- #import "Renderer.h"
- #import "LenzHeader.h"
- CGFloat const PanoramaGuideViewWOrH = 120;
- @interface PanoramaGuideViewPreviewContainer : MTKView
- @end
- @implementation PanoramaGuideViewPreviewContainer
- @end
- @interface PanoramaGuideView() <MTKViewDelegate>
- @property (nonatomic, strong) PanoramaGuideViewPreviewContainer* container;
- @property (nonatomic, assign) CGFloat aspect;
- @property (nonatomic, assign) CGFloat offset;
- @property (nonatomic, strong) NSTimer* timer;
- @property (nonatomic, strong) UIImageView *whiteArrow;
- @property (nonatomic, strong) UIView* line;
- @property (nonatomic, weak) UIView* superV;
- @property (nonatomic, strong)YYLabel *label;
- @property (nonatomic) UIImageView *showImageView;
- @property (nonatomic) PanoramaArrowDir lastArrowDir;
- @property (nonatomic) NSNumber *offSetTop;
- @property (nonatomic) NSNumber *offSetLeft;
- @property (nonatomic) PanoramaOrientationViewDirectionEnum currentDirection;
- @end
- @implementation PanoramaGuideView
- - (instancetype)init{
- self = [super init];
- self.backgroundColor = [UIColor jk_colorWithHexString:@"#000000" andAlpha:0.5];
- [self addSubview:self.showImageView];
- self.offSetTop = @((120-38)/2);
- self.offSetLeft = @((120-38)/2);
- return self;
- }
- - (void)willMoveToSuperview:(nullable UIView *)newSuperview;{
- [super willMoveToSuperview:newSuperview];
- self.superV = newSuperview;
- }
- - (void)updatePreviewAspect:(CGFloat)aspect{
- if(aspect > 0.01){
- self.aspect = 1.0 / aspect;
- }
- else{
- self.aspect = 1;
- }
-
- [self.container mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.top.equalTo(self).offset(self.offset);
- make.height.equalTo(self);
- // it means aspect > 0
- make.width.equalTo(self.container.mas_height).multipliedBy(self.aspect);
- }];
- }
- - (void)updateOffset:(CGFloat)offset{
- self.offset = offset;
- [self.container mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(self.offset);
- make.top.equalTo(self);
- make.height.equalTo(self);
- make.width.equalTo(self.container.mas_height).multipliedBy(self.aspect);
- }];
- }
- - (void)direction:(PanoramaOrientationViewDirectionEnum)dir{
- self.currentDirection = dir;
- [self insertSubview:self.line atIndex:0];
- self.line.hidden = YES;
- // self.label.hidden = YES;
- [self.superV addSubview:self.label];
- [self addSubview:self.whiteArrow];
- [self.line mas_remakeConstraints:^(MASConstraintMaker *make) {
- switch (dir) {
- case PanoramaOrientationViewLeft:
- case PanoramaOrientationViewRight:
- {
- make.left.right.offset(0);
- make.height.offset(0.5);
- make.centerY.mas_equalTo(self);
- }
- break;
- case PanoramaOrientationViewUp:
- case PanoramaOrientationViewDown:
- {
- make.top.bottom.offset(0);
- make.width.offset(0.5);
- make.centerX.mas_equalTo(self);
- }
- break;
-
- default:
- break;
- }
- }];
-
-
- // [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- // switch (dir) {
- // case PanoramaOrientationViewLeft:
- // case PanoramaOrientationViewRight: // 横
- // {
- // make.top.mas_equalTo(self.mas_bottom).offset(5);
- // make.centerX.mas_equalTo(self.superV);
- // make.height.offset(20);
- // make.width.offset(160);
- // self.label.verticalForm = NO;
- // }
- // break;
- // case PanoramaOrientationViewUp:
- // case PanoramaOrientationViewDown: // 上下
- // {
- // make.right.mas_equalTo(self.mas_left).offset(-5);
- // make.centerY.mas_equalTo(self.superV);
- // make.width.offset(20);
- // make.height.offset(160);
- // self.label.verticalForm = YES;
- // }
- // break;
- //
- // default:
- // break;
- // }
- // }];
- [self updatePromptLabel];
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- switch (dir) {
- case PanoramaOrientationViewUp: {
- make.left.right.top.mas_equalTo(0);
- make.height.mas_equalTo(0);
- make.height.mas_lessThanOrEqualTo(self);
- }
- break;
- case PanoramaOrientationViewDown: {
- make.left.right.bottom.mas_equalTo(0);
- make.height.mas_equalTo(0);
- }
- break;
- case PanoramaOrientationViewLeft: {
- make.left.top.bottom.mas_equalTo(0);
- make.width.mas_equalTo(0);
- make.width.mas_lessThanOrEqualTo(self);
- }
- break;
- case PanoramaOrientationViewRight: {
- make.top.right.bottom.mas_equalTo(0);
- make.width.mas_equalTo(0);
- make.width.mas_lessThanOrEqualTo(self);
-
- }
- break;
- default:
- break;
- }
- }];
-
- [UIView animateWithDuration:0.2 animations:^{
- __block UIImage *arrow = nil;
- /// 白色的箭头
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- switch (dir) {
- case PanoramaOrientationViewLeft: //左
- {
-
- make.centerY.mas_equalTo(self);
- make.left.offset(0);
- arrow = [UIImage loadNamed:@"ai_right_arrow"];
- }
- break;
- case PanoramaOrientationViewRight: // 右
- {
- make.centerY.mas_equalTo(self);
- make.right.offset(0);
- arrow = [UIImage loadNamed:@"ai_left_arrow"];
- }
- break;
- case PanoramaOrientationViewUp: //上
- {
-
- make.centerX.mas_equalTo(self);
- make.top.offset(0);
- arrow = [UIImage loadNamed:@"ai_down_arrow"];
- }
- break;
- case PanoramaOrientationViewDown: // 下
- {
- make.centerX.mas_equalTo(self);
- make.bottom.offset(0);
- arrow = [UIImage loadNamed:@"ai_up_arrow"];
- }
- break;
-
- default:
- break;
- }
- }];
- self.whiteArrow.image = arrow;
- [self setNeedsLayout];
- [self layoutIfNeeded];
- } completion:^(BOOL finished) {
- self.line.hidden = NO;
- // self.label.hidden = NO;
- }];
- }
- - (void)updatePromptLabel {
-
- // self.backgroundColor = [UIColor redColor];
- // self.superV.backgroundColor = [UIColor yellowColor];
- self.label.transform = CGAffineTransformMakeRotation(0);
- switch (self.dir) {
- case TgDirectionPortrait: {
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- switch (self.orginDir) {
- case PanoramaOrientationViewLeft:
- case PanoramaOrientationViewRight: // 横
- {
- make.top.mas_equalTo(self.mas_bottom).offset(5);
- make.centerX.mas_equalTo(self.superV);
- make.height.offset(20);
- make.width.offset(160);
- self.label.verticalForm = NO;
- }
- break;
- case PanoramaOrientationViewUp:
- case PanoramaOrientationViewDown: // 上下
- {
- make.right.mas_equalTo(self.mas_left).offset(-5);
- make.centerY.mas_equalTo(self.superV);
- make.width.offset(20);
- make.height.offset(160);
- self.label.verticalForm = YES;
- }
- break;
-
- default:
- break;
- }
- }];
-
- }
- break;
- case TgDirectionDown: {
- switch (self.orginDir) {
- case PanoramaOrientationViewLeft: {
- self.label.transform = CGAffineTransformMakeRotation(-M_PI);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(self.mas_top).mas_offset(-20);
- make.centerX.mas_equalTo(self);
- make.height.offset(20);
- make.width.offset(160);
- self.label.verticalForm = NO;
- }];
- }
- break;
- case PanoramaOrientationViewRight: // 横
- {
- // self.label.transform = CGAffineTransformMakeRotation(0);
- self.label.transform = CGAffineTransformMakeRotation(-M_PI/2);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.mas_right).offset(-60);
- make.centerY.mas_equalTo(self);
- make.height.offset(20);
- make.width.offset(160);
- self.label.verticalForm = NO;
- }];
- }
- break;
- case PanoramaOrientationViewUp: {
- self.label.transform = CGAffineTransformMakeRotation(M_PI);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.mas_left).offset(-5);
- make.centerY.mas_equalTo(self.superV);
- make.width.offset(20);
- make.height.offset(160);
- self.label.verticalForm = YES;
- }];
- }
- break;
- case PanoramaOrientationViewDown: // 上下
- {
- self.label.transform = CGAffineTransformMakeRotation(M_PI);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.mas_left).offset(-5);
- make.centerY.mas_equalTo(self.superV);
- make.width.offset(20);
- make.height.offset(160);
- self.label.verticalForm = YES;
- }];
- }
- break;
-
- default:
- break;
- }
-
- }
- break;
- case TgDirectionLeft: {
- switch (self.orginDir) {
- case PanoramaOrientationViewLeft: {
- // self.label.transform = CGAffineTransformMakeRotation(0);
- self.label.transform = CGAffineTransformMakeRotation(M_PI/2);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.mas_left).mas_offset(60);
- make.centerY.mas_equalTo(self);
- make.height.offset(20);
- make.width.offset(160);
- self.label.verticalForm = NO;
- }];
- }
- break;
- case PanoramaOrientationViewRight: // 横
- {
-
- // self.label.transform = CGAffineTransformMakeRotation(0);
- self.label.transform = CGAffineTransformMakeRotation(M_PI/2);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.mas_left).mas_offset(60);
- make.centerY.mas_equalTo(self);
- make.height.offset(20);
- make.width.offset(160);
- self.label.verticalForm = NO;
- }];
- }
- break;
- case PanoramaOrientationViewUp:{
- self.label.transform = CGAffineTransformMakeRotation(M_PI/2);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.mas_bottom).offset(-60);
- make.centerX.mas_equalTo(self.superV);
- make.width.offset(20);
- make.height.offset(160);
- self.label.verticalForm = YES;
- }];
- }
- break;
- case PanoramaOrientationViewDown: // 上下
- {
- self.label.transform = CGAffineTransformMakeRotation(M_PI/2);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.mas_bottom).offset(-60);
- make.centerX.mas_equalTo(self.superV);
- make.width.offset(20);
- make.height.offset(160);
- self.label.verticalForm = YES;
- }];
- }
- break;
-
- default:
- break;
- }
-
-
- }
- break;
- case TgDirectionRight: {
- switch (self.orginDir) {
- case PanoramaOrientationViewLeft: {
- self.label.transform = CGAffineTransformMakeRotation(-M_PI/2);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.mas_right).offset(-60);
- make.centerY.mas_equalTo(self);
- make.height.offset(20);
- make.width.offset(160);
- self.label.verticalForm = NO;
- }];
- }
- break;
- case PanoramaOrientationViewRight: // 横
- {
- self.label.transform = CGAffineTransformMakeRotation(-M_PI/2);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.mas_right).offset(-60);
- make.centerY.mas_equalTo(self);
- make.height.offset(20);
- make.width.offset(160);
- self.label.verticalForm = NO;
- }];
- }
- break;
- case PanoramaOrientationViewUp:{
- self.label.transform = CGAffineTransformMakeRotation(-M_PI/2);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.mas_bottom).offset(-60);
- make.centerX.mas_equalTo(self.superV);
- make.width.offset(20);
- make.height.offset(160);
- self.label.verticalForm = YES;
- }];
- }
- break;
- case PanoramaOrientationViewDown: // 上下
- {
- self.label.transform = CGAffineTransformMakeRotation(-M_PI/2);
- [self.label mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.mas_bottom).offset(-60);
- make.centerX.mas_equalTo(self.superV);
- make.width.offset(20);
- make.height.offset(160);
- self.label.verticalForm = YES;
- }];
- }
- break;
-
- default:
- break;
- }
- }
- break;
-
- default:
- break;
- }
-
- }
- - (void)showImageWith:(UIImage * _Nullable)image {
-
- // self.lastImage = image;
- dispatch_async(dispatch_get_main_queue(), ^{
- __block CGFloat imageWH = 0;
- if (!image) {
- self.offSetTop = @((120-38)/2);
- self.offSetLeft = @((120-38)/2);
- }
-
- self.showImageView.image = image;
- [UIView animateWithDuration:.15 animations:^{
- if (self.dir == TgDirectionPortrait) {
- if (self.orginDir == PanoramaOrientationViewDown) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.height)/image.size.width;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(imageWH);
- make.height.mas_lessThanOrEqualTo(self);
- make.left.right.bottom.mas_equalTo(0);
- }];
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_offset(-imageWH);
- make.left.mas_equalTo(self.offSetLeft.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewUp) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.height)/image.size.width;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(0);
- make.height.mas_equalTo(imageWH);
- make.height.mas_lessThanOrEqualTo(self);
- }];
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(imageWH);
- make.left.mas_equalTo(self.offSetLeft.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewLeft) {
-
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.width)/image.size.height;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(imageWH);
- make.width.mas_lessThanOrEqualTo(self);
- make.left.top.bottom.mas_equalTo(0);
- }];
-
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(imageWH);
- make.top.mas_equalTo(self.offSetTop.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewRight) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.width)/image.size.height;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(imageWH);
- make.width.mas_lessThanOrEqualTo(self);
- make.top.right.bottom.mas_equalTo(0);
- }];
-
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_offset(-imageWH);
- make.top.mas_equalTo(self.offSetTop.doubleValue);
- }];
- }
-
- } else if (self.dir == TgDirectionLeft) {
- if (self.orginDir == PanoramaOrientationViewLeft) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.height)/image.size.width;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(0);
- make.height.mas_equalTo(imageWH);
- make.height.mas_lessThanOrEqualTo(self);
- }];
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(imageWH);
- make.left.mas_equalTo(self.offSetLeft.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewRight) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.height)/image.size.width;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(imageWH);
- make.height.mas_lessThanOrEqualTo(self);
- make.left.right.bottom.mas_equalTo(0);
- }];
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_offset(-imageWH);
- make.left.mas_equalTo(self.offSetLeft.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewUp) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.width)/image.size.height;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(imageWH);
- make.width.mas_lessThanOrEqualTo(self);
- make.top.right.bottom.mas_equalTo(0);
- }];
-
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_offset(-imageWH);
- make.top.mas_equalTo(self.offSetTop.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewDown) {
-
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.width)/image.size.height;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(imageWH);
- make.width.mas_lessThanOrEqualTo(self);
- make.left.top.bottom.mas_equalTo(0);
- }];
-
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(imageWH);
- make.top.mas_equalTo(self.offSetTop.doubleValue);
- }];
- }
-
- } else if (self.dir == TgDirectionRight) {
- if (self.orginDir == PanoramaOrientationViewLeft) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.height)/image.size.width;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(imageWH);
- make.height.mas_lessThanOrEqualTo(self);
- make.left.right.bottom.mas_equalTo(0);
- }];
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_offset(-imageWH);
- make.left.mas_equalTo(self.offSetLeft.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewRight) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.height)/image.size.width;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(0);
- make.height.mas_equalTo(imageWH);
- make.height.mas_lessThanOrEqualTo(self);
- }];
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(imageWH);
- make.left.mas_equalTo(self.offSetLeft.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewUp) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.width)/image.size.height;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(imageWH);
- make.width.mas_lessThanOrEqualTo(self);
- make.left.top.bottom.mas_equalTo(0);
- }];
-
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(imageWH);
- make.top.mas_equalTo(self.offSetTop.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewDown) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.width)/image.size.height;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(imageWH);
- make.width.mas_lessThanOrEqualTo(self);
- make.top.right.bottom.mas_equalTo(0);
- }];
-
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_offset(-imageWH);
- make.top.mas_equalTo(self.offSetTop.doubleValue);
- }];
- }
- } else if (self.dir == TgDirectionDown) {
- if (self.orginDir == PanoramaOrientationViewLeft) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.width)/image.size.height;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(imageWH);
- make.width.mas_lessThanOrEqualTo(self);
- make.top.right.bottom.mas_equalTo(0);
- }];
-
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_offset(-imageWH);
- make.top.mas_equalTo(self.offSetTop.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewRight) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.width)/image.size.height;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(imageWH);
- make.width.mas_lessThanOrEqualTo(self);
- make.left.top.bottom.mas_equalTo(0);
- }];
-
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(imageWH);
- make.top.mas_equalTo(self.offSetTop.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewUp) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.height)/image.size.width;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(imageWH);
- make.height.mas_lessThanOrEqualTo(self);
- make.left.right.bottom.mas_equalTo(0);
- }];
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_offset(-imageWH);
- make.left.mas_equalTo(self.offSetLeft.doubleValue);
- }];
- } else if (self.orginDir == PanoramaOrientationViewDown) {
- if (image) {
- imageWH = (PanoramaGuideViewWOrH * image.size.height)/image.size.width;
- }
- [self.showImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(0);
- make.height.mas_equalTo(imageWH);
- make.height.mas_lessThanOrEqualTo(self);
- }];
- [self.whiteArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(imageWH);
- make.left.mas_equalTo(self.offSetLeft.doubleValue);
- }];
- }
- }
- [self setNeedsLayout];
- [self layoutIfNeeded];
- }];
- });
-
-
-
- }
- - (void)updateArrowWith:(PanoramaArrowDir)arrowDir dir:(PanoramaOrientationViewDirectionEnum)dir {
- // self.lastArrowDir = arrowDir;
- dispatch_async(dispatch_get_main_queue(), ^{
- if (!self.showImageView.image) {
- return;
- }
- if (self.dir == TgDirectionPortrait || self.dir == TgDirectionDown) {
- if (dir == PanoramaOrientationViewDown || dir == PanoramaOrientationViewUp) {
- if (arrowDir == PanoramaArrowDirCenter) {
- self.offSetLeft = @((120-38)/2);
- } else if (arrowDir == PanoramaArrowDirLeft) {
- self.offSetLeft = @(0);
- } else if (arrowDir == PanoramaArrowDirRight) {
- self.offSetLeft = @(120-38);
- }
- } else if (dir == PanoramaOrientationViewLeft || dir == PanoramaOrientationViewRight) {
- if (arrowDir == PanoramaArrowDirCenter) {
- self.offSetTop = @((120-38)/2);
- } else if (arrowDir == PanoramaArrowDirUp) {
- self.offSetTop = @(0);
- } else if (arrowDir == PanoramaArrowDirDown) {
- self.offSetTop = @(120-38);
- }
-
- }
- } else if (self.dir == TgDirectionLeft || self.dir == TgDirectionRight) {
- if (dir == PanoramaOrientationViewLeft || dir == PanoramaOrientationViewRight) {
- if (arrowDir == PanoramaArrowDirCenter) {
- self.offSetLeft = @((120-38)/2);
- } else if (arrowDir == PanoramaArrowDirLeft) {
- self.offSetLeft = @(0);
- } else if (arrowDir == PanoramaArrowDirRight) {
- self.offSetLeft = @(120-38);
- }
- } else {
- if (arrowDir == PanoramaArrowDirCenter) {
- self.offSetTop = @((120-38)/2);
- } else if (arrowDir == PanoramaArrowDirUp) {
- self.offSetTop = @(0);
- } else if (arrowDir == PanoramaArrowDirDown) {
- self.offSetTop = @(120-38);
- }
- }
- }
-
- [self showImageWith:self.showImageView.image];
- });
- }
- - (void)clearImage {
- dispatch_async(dispatch_get_main_queue(), ^{
- self.showImageView.image = nil;
- });
- }
- - (UIImage *)showDir:(PanoramaOrientationViewDirectionEnum)dir image:(UIImage *)image {
- switch (dir) {
- case PanoramaOrientationViewUp: {
- UIImage *flipImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationRight];
- return flipImage;
- }
- break;
- case PanoramaOrientationViewDown: {
- UIImage *flipImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationLeft];
- return flipImage;
- }
-
-
- break;
- case PanoramaOrientationViewLeft: {
- return image;
- }
-
- break;
- case PanoramaOrientationViewRight: {
- UIImage *flipImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUpMirrored];
- return flipImage;
- }
- break;
-
- default:
- break;
- }
-
- return nil;
- }
- - (void)setHidden:(BOOL)hidden{
- [super setHidden:hidden];
- self.label.hidden = hidden;
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
-
- self.container = [[PanoramaGuideViewPreviewContainer alloc] initWithFrame:CGRectMake(0, 0, 50, 50) device:[Renderer shared].device];
- self.container.clearColor = MTLClearColorMake(0, 0, 0, 1);
- self.container.backgroundColor = [UIColor redColor];
- [self addSubview:self.container];
- self.container.delegate = self;
- self.container.sampleCount = 1;
- self.container.colorPixelFormat = MTLPixelFormatBGRA8Unorm;
- [self.container mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.equalTo(self);
- make.height.equalTo(self);
- make.width.equalTo(@(50));
- }];
-
- [[Renderer shared] setup];
-
- }
- - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size{
- [[Renderer shared] mtkView:view drawableSizeWillChange:size];
- }
- - (void)drawInMTKView:(MTKView *)view{
- [[Renderer shared] drawInMTKView:view];
- }
- - (YYLabel *)label{
- if (_label == nil) {
- NSAttributedString *att = [[NSAttributedString alloc]initWithString:@"请沿箭头方向匀速拍摄"];
- _label = [[YYLabel alloc]init];
- // _label.numberOfLines = 0;
- _label.backgroundColor = [UIColor jk_colorWithHexString:@"000000" andAlpha:0.35];
- _label.attributedText = att;
- _label.textAlignment = NSTextAlignmentCenter;
- _label.layer.cornerRadius = 3;
- _label.layer.masksToBounds = YES;
- // _label.textVerticalAlignment = YYTextVerticalAlignmentCenter; // 文字置顶显示
- _label.textColor = UIColor.whiteColor;
- }
- return _label;
- }
- - (UIImageView *)showImageView {
- if (!_showImageView) {
- _showImageView = [[UIImageView alloc]init];
- _showImageView.contentMode = UIViewContentModeScaleAspectFill;
- _showImageView.clipsToBounds = YES;
- }
- return _showImageView;
- }
- - (UIView *)line{
- if (_line == nil) {
- _line = [[UIView alloc]init];
- _line.backgroundColor = UIColor.yellowColor;
- }
- return _line;
- }
- - (UIImageView *)whiteArrow{
- if (_whiteArrow == nil) {
- _whiteArrow = [[UIImageView alloc]initWithImage:[UIImage loadNamed:@"ai_right_arrow"]];
- }
- return _whiteArrow;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|