iOS:練習題中如何用技術去實現一個連線題

一、介紹

本人做的app涉及的是教育行業,所以關于練習題的開發肯定是家常便飯。例如,選擇題、填空題、連線題、判斷題等,每一種題型都需要技術去實現,沒啥多大難度,這里呢,就給出實現連線題的核心代碼吧。過了年后,好久沒寫筆記了,今天就簡單開始吧~~~

?

二、思想

采用上下文在畫圖的方法,首先確定起點和終點的坐標,然后通過兩點畫一條直線。

?

三、代碼

(1)常量定義

lianXianHeader.h

//
//  LianXianHeader.h
//  LianxianDemo
//
//  Created by 夏遠全 on 2018/2/9.
//  Copyright ? 2018年 beijing. All rights reserved.
//

#ifndef LianXianHeader_h
#define LianXianHeader_hstatic CGFloat const BWidth   = 60;  //按鈕的寬度
static CGFloat const BHeight  = 40;  //按鈕的高度
static CGFloat const margin   = 40;  //按鈕與屏幕的左邊距、右邊距
static CGFloat const Lpadding = 20;  //左邊按鈕上下間距
static CGFloat const Rpadding = 40;  //右邊按鈕上下間距static NSString* const kBeginPositionNotification = @"kBeginPositionNotification";
static NSString* const kEndPositionNotification   = @"kEndPositionNotification";
static NSString* const kClearAllLineNotification  = @"kClearAllLineNotification";
static NSString* const kFreshDrawLineNotification = @"kFreshDrawLineNotification";#endif /* LianXianHeader_h */
View Code

?

(2)連線模型

lianXianModel.h

//
//  LianXianModel.h
//  LianxianDemo
//
//  Created by 夏遠全 on 2018/2/8.
//  Copyright ? 2018年 beijing. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>@interface LianXianModel : NSObject
@property (nonatomic, strong) NSArray  *questions;
@property (nonatomic, strong) NSArray  *options;
@property (nonatomic, strong) NSArray  *relationships;
@end
View Code

lianXianModel.m

//
//  LianXianModel.m
//  LianxianDemo
//
//  Created by 夏遠全 on 2018/2/8.
//  Copyright ? 2018年 beijing. All rights reserved.
//

#import "LianXianModel.h"@implementation LianXianModel@end
View Code

?

(3)繪制連線

lianXianDrawView.h

//
//  LianxianDrawView.h
//  Ubbsz
//
//  Created by 夏遠全 on 2018/2/9.
//  Copyright ? 2018年 beijing. All rights reserved.
//
//

#import <UIKit/UIKit.h>@interface LianxianDrawView : UIView@end
View Code

lianXianDrawView.m

//
//  LianxianDrawView.m
//  Ubbsz
//
//  Created by 夏遠全 on 2018/2/9.
//  Copyright ? 2018年 beijing. All rights reserved.
//
#import "LianxianDrawView.h"
#import "LianXianHeader.h"@interface LianxianDrawView()
{NSMutableArray *pointArray; //存儲當前的一對坐標,起始點和終止點NSMutableArray *lineArray;  //存儲全部的連線,每一條連線就是一對坐標NSString       *startPointString; //當前起點NSString       *endPointString;   //當前起點
    CGFloat        lineWidth;
}@end@implementation LianxianDrawView//對進行重寫,以便在視圖初始化的時候創建并設置自定義的Context
- (id)initWithFrame:(CGRect)frame
{if (self = [super initWithFrame:frame]) {[self setupDefaultValue];[self regesterNotification];}return self;
}//初始值
- (void)setupDefaultValue{pointArray=[[NSMutableArray alloc]init];lineArray=[[NSMutableArray alloc]init];lineWidth = 2.0f;self.backgroundColor = [UIColor colorWithRed:238/255.0 green:243/255.0  blue:248/255.0  alpha:1];
}//注冊通知
- (void)regesterNotification{[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toucheBegin:) name:kBeginPositionNotification object:nil];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toucheEnd:) name:kEndPositionNotification object:nil];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearLine:) name:kClearAllLineNotification object:nil];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(freshNeedsDisplay:) name:kFreshDrawLineNotification object:nil];
}//對drawRect進行重寫
- (void)drawRect:(CGRect)rect
{//獲取當前上下文,CGContextRef context=UIGraphicsGetCurrentContext();CGContextBeginPath(context);CGContextSetLineWidth(context, lineWidth);//線條拐角樣式,設置為平滑
    CGContextSetLineJoin(context,kCGLineJoinRound);//線條開始樣式,設置為平滑
    CGContextSetLineCap(context, kCGLineCapRound);//查看lineArray數組里是否有線條,有就將之前畫的重繪,沒有只畫當前線條if ([lineArray count] > 0) {for (int i=0; i < [lineArray count]; i++) {NSArray * array=[NSArray arrayWithArray:[lineArray objectAtIndex:i]];if ([array count] > 0 && [array count]%2 == 0) {CGContextBeginPath(context);CGPoint myStartPoint = CGPointFromString(array.firstObject);CGContextMoveToPoint(context, myStartPoint.x, myStartPoint.y);CGPoint myEndPoint = CGPointFromString(array.lastObject);CGContextAddLineToPoint(context, myEndPoint.x,myEndPoint.y);CGContextSetStrokeColorWithColor(context,[[UIColor grayColor] CGColor]);CGContextSetLineWidth(context, lineWidth);CGContextStrokePath(context);}}}
}//接收起點按鈕點擊通知事件
- (void)toucheBegin:(NSNotification *)notification{CGRect beginFrame = [notification.object CGRectValue];CGPoint startPoint = CGPointMake(CGRectGetMaxX(beginFrame), CGRectGetMidY(beginFrame));startPointString = NSStringFromCGPoint(startPoint);if (pointArray.count==0) {[pointArray addObject:startPointString];}else{[pointArray replaceObjectAtIndex:0 withObject:startPointString];}
}//接收終點按鈕點擊通知事件
- (void)toucheEnd:(NSNotification *)notification{CGRect endFrame = [notification.object CGRectValue];CGPoint endPoint = CGPointMake(CGRectGetMinX(endFrame), CGRectGetMidY(endFrame));endPointString = NSStringFromCGPoint(endPoint);if (pointArray.count==2) {[pointArray replaceObjectAtIndex:1 withObject:endPointString];}else{[pointArray addObject:endPointString];}[self clearSomeHistoryLineView];[self addLA];[self setNeedsDisplay];
}//接收清除按鈕點擊通知事件
- (void)clearLine:(NSNotification *)notification{[self clearAllLineView];
}//接收重新繪制通知事件
- (void)freshNeedsDisplay:(NSNotification *)notification{NSArray *relationslineArray = notification.object;lineArray = [NSMutableArray arrayWithArray:relationslineArray];[self setNeedsDisplay];
}//添加連線
-(void)addLA{NSArray *array = [NSArray arrayWithArray:pointArray];[lineArray addObject:array];[pointArray removeAllObjects];
}//清除所有的連線
- (void)clearAllLineView
{[pointArray removeAllObjects];[lineArray removeAllObjects];[self setNeedsDisplay];
}//移除歷史交叉重復的連線
- (void)clearSomeHistoryLineView{NSMutableArray *arrayM = [NSMutableArray array];for (int i=0; i < [lineArray count]; i++) {NSArray *array = [NSArray arrayWithArray:[lineArray objectAtIndex:i]];if ([array count] > 0) {NSString *hisBePointString = array.firstObject;NSString *hisEnPointString = array.lastObject;if ([startPointString isEqualToString:hisBePointString] || [endPointString isEqualToString:hisEnPointString]) {[arrayM addObject:array];}}}[lineArray removeObjectsInArray:arrayM];
}//移除通知
-(void)dealloc{[[NSNotificationCenter defaultCenter] removeObserver:self];
}@end
View Code

?

(4)計算尺寸

LianXianFrameUitity.h

//
//  LianXianSizeUitity.h
//  LianxianDemo
//
//  Created by 夏遠全 on 2018/2/9.
//  Copyright ? 2018年 beijing. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "LianXianModel.h"@interface LianXianFrameUitity : NSObject+ (CGRect)calculateSizeWithModel:(LianXianModel *)lianxianModel;@end
View Code

LianXianFrameUitity.m?

//
//  LianXianSizeUitity.m
//  LianxianDemo
//
//  Created by 夏遠全 on 2018/2/9.
//  Copyright ? 2018年 beijing. All rights reserved.
//

#import "LianXianFrameUitity.h"
#import "LianXianHeader.h"@implementation LianXianFrameUitity+ (CGRect)calculateSizeWithModel:(LianXianModel *)lianxianModel{NSUInteger questionsCount = lianxianModel.questions.count;NSUInteger optionsCount = lianxianModel.options.count;CGFloat LHeight = questionsCount * (BHeight+Lpadding) + Lpadding;CGFloat RHeight = optionsCount * (BHeight+Rpadding) + Rpadding;CGFloat kWidth  = [UIScreen mainScreen].bounds.size.width; //默認寬度為屏幕的寬return CGRectMake(0, 0, kWidth, MAX(LHeight, RHeight));
}@end
View Code

?

(5)創建組件

LianXianComponentsView.h

//
//  LianXianComponentsView.h
//  LianxianDemo
//
//  Created by 夏遠全 on 2018/2/6.
//  Copyright ? 2018年 beijing. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "LianXianModel.h"@interface LianXianComponentsView : UIView
@property (nonatomic, strong) LianXianModel *lianxianModel;
@end
View Code

LianXianComponentsView.m

//
//  LianXianComponentsView.m
//  LianxianDemo
//
//  Created by 夏遠全 on 2018/2/6.
//  Copyright ? 2018年 beijing. All rights reserved.
//

#import "LianXianComponentsView.h"
#import "LianxianDrawView.h"
#import "LianXianHeader.h"@interface LianXianComponentsView() {NSMutableArray *_leftBtns;NSMutableArray *_rightBtns;UIButton       *currentLeftBtn;CGFloat        borderWith;
}@end@implementation LianXianComponentsView//對進行重寫,以便在視圖初始化的時候創建并設置自定義的Context
- (id)initWithFrame:(CGRect)frame
{if (self = [super initWithFrame:frame]) {[self setupDefalutValue];}return self;
}//設置默認值
- (void)setupDefalutValue{self.backgroundColor = [UIColor clearColor];borderWith = 2.5;[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restStatus:) name:kClearAllLineNotification object:nil];
}//接收模型
-(void)setLianxianModel:(LianXianModel *)lianxianModel{_lianxianModel = lianxianModel;[self setupLianXianUnit];if (lianxianModel && lianxianModel.relationships.count>0) {[self showLianXianResult];}else{[self listClickLeftButton];}
}//繪制連線選項
- (void)setupLianXianUnit{_leftBtns  = [[NSMutableArray array] init];_rightBtns = [[NSMutableArray array] init];CGFloat kWidth   = self.frame.size.width;CGFloat kHeight  = self.frame.size.height;CGFloat LY = (kHeight-(BHeight+Lpadding)*(self.lianxianModel.questions.count-1) - BHeight)/2;CGFloat RY = (kHeight-(BHeight+Rpadding)*(self.lianxianModel.options.count-1) - BHeight)/2;for (NSInteger i =0; i < self.lianxianModel.questions.count; i++) {UIButton *btn = [self createButtonWithFrame:CGRectMake(margin, LY+(BHeight+Lpadding)*i, BWidth, BHeight) title:[NSString stringWithFormat:@"%@",self.lianxianModel.questions[i]] tag:i];[self addSubview:btn];[_leftBtns addObject:btn];}for (NSInteger i =0; i< self.lianxianModel.options.count; i++) {UIButton *btn = [self createButtonWithFrame:CGRectMake(kWidth-margin-BWidth, RY+(BHeight+Rpadding)*i, BWidth, BHeight) title:[NSString stringWithFormat:@"%@",self.lianxianModel.options[i]] tag:i];[self addSubview:btn];[_rightBtns addObject:btn];}
}-(UIButton *)createButtonWithFrame:(CGRect)frame title:(NSString *)title tag:(NSInteger)tag{UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];btn.frame = frame;btn.layer.cornerRadius = 5.0;btn.layer.borderColor = [UIColor lightGrayColor].CGColor;btn.layer.borderWidth = borderWith;btn.layer.masksToBounds = YES;btn.tag = tag;[btn setBackgroundImage:[self imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal];[btn setBackgroundImage:[self imageWithColor:[UIColor colorWithRed:138/255.0 green:193/255.0 blue:211/255.0 alpha:1]] forState:UIControlStateHighlighted];[btn setBackgroundImage:[self imageWithColor:[UIColor colorWithRed:138/255.0 green:193/255.0 blue:211/255.0 alpha:1]] forState:UIControlStateSelected];[btn addTarget:self action:@selector(tapBtn:) forControlEvents:UIControlEventTouchUpInside];[btn setTitle:title forState:UIControlStateNormal];[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];return btn;
}- (UIImage *)imageWithColor:(UIColor *)color
{CGFloat imageW = 20;CGFloat imageH = 20;UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageW, imageH), NO, 0.0);[color set];UIRectFill(CGRectMake(0, 0, imageW, imageH));UIImage *image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return image;
}-(void)tapBtn:(UIButton *)btn{//判斷左邊按鈕是否處于選擇狀態,只有首先左邊處于此狀態下,右邊的按鈕點擊才能進行連線操作(當前僅支持單向連線)if ([_rightBtns containsObject:btn]) {BOOL isLeftBtnSelected = NO;for (UIButton *leftBtn in _leftBtns) {if (leftBtn.selected) {isLeftBtnSelected = YES;break;}}if (!isLeftBtnSelected) {return;}}if ([_leftBtns containsObject:btn]) {//設置連線起點currentLeftBtn.selected = NO;currentLeftBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;btn.selected = YES;currentLeftBtn = btn;currentLeftBtn.layer.borderColor = [UIColor colorWithRed:32/255.0 green:199/255.0 blue:251/255.0 alpha:1].CGColor;//設置終點按鈕可以選中狀態for (UIButton *rightBtn in _rightBtns) {rightBtn.layer.borderColor = [UIColor colorWithRed:32/255.0 green:199/255.0 blue:251/255.0 alpha:1].CGColor;}//發送起點通知[[NSNotificationCenter defaultCenter] postNotificationName:kBeginPositionNotification object:[NSValue valueWithCGRect:btn.frame]];}if ([_rightBtns containsObject:btn]) {for (UIButton *leftBtn in _leftBtns) {if (leftBtn.selected) {//發送終點通知[[NSNotificationCenter defaultCenter] postNotificationName:kEndPositionNotification object:[NSValue valueWithCGRect:btn.frame]];//自動設置起始選擇按鈕
                [self listClickLeftButton];break;}}}
}//自動設置起始選擇按鈕
- (void)listClickLeftButton{if (!currentLeftBtn) {[self tapBtn:_leftBtns[0]];return;}NSUInteger tag = currentLeftBtn.tag;if (tag < _leftBtns.count-1) {  //自動下移[self tapBtn:_leftBtns[tag+1]];}else{[self tapBtn:_leftBtns[0]]; //重新開始
    }
}//繪制默認已經連線的選項,此處僅僅做成績預覽使用,不能再編輯
- (void)showLianXianResult{for (UIButton *leftBtn in _leftBtns) {leftBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;leftBtn.selected = leftBtn.userInteractionEnabled = NO;}for (UIButton *rightBtn in _rightBtns) {rightBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;rightBtn.selected = rightBtn.userInteractionEnabled = NO;}if (self.lianxianModel.relationships.count == 0) {return;}NSMutableArray *relationslineArray = [NSMutableArray array];for (NSString *result in self.lianxianModel.relationships) {NSString *question = [[result componentsSeparatedByString:@"-"] firstObject];NSString *option   = [[result componentsSeparatedByString:@"-"] lastObject];NSMutableArray *pointArray = [NSMutableArray array];for (UIButton *leftBtn in _leftBtns) {if ([leftBtn.currentTitle isEqualToString:question]) {CGPoint startPoint = CGPointMake(CGRectGetMaxX(leftBtn.frame), CGRectGetMidY(leftBtn.frame));NSString *startPointString = NSStringFromCGPoint(startPoint);[pointArray addObject:startPointString];break;}}for (UIButton *rightBtn in _rightBtns) {if ([rightBtn.currentTitle isEqualToString:option]) {CGPoint endPoint = CGPointMake(CGRectGetMinX(rightBtn.frame), CGRectGetMidY(rightBtn.frame));NSString *endPointString = NSStringFromCGPoint(endPoint);[pointArray addObject:endPointString];break;}}[relationslineArray addObject:pointArray];}if (relationslineArray.count > 0) {[[NSNotificationCenter defaultCenter] postNotificationName:kFreshDrawLineNotification object:relationslineArray];}
}//重置初始狀態
- (void)restStatus:(NSNotification *)notification{for (UIButton *leftBtn in _leftBtns) {leftBtn.selected = NO;leftBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;[self tapBtn:_leftBtns[0]]; //重新開始
    }
}@end
View Code

?

(6)連線容器

LianXianContainerView.h

//
//  LianXianContainerView.h
//  LianxianDemo
//
//  Created by 夏遠全 on 2018/2/8.
//  Copyright ? 2018年 beijing. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "LianXianComponentsView.h"
#import "LianxianDrawView.h"@interface LianXianContainerView : UIView
@property (nonatomic, strong) LianXianComponentsView *componentsView;
@property (nonatomic, strong) LianxianDrawView *lianXianView;
@end
View Code

LianXianContainerView.m

//
//  LianXianContainerView.m
//  LianxianDemo
//
//  Created by 夏遠全 on 2018/2/8.
//  Copyright ? 2018年 beijing. All rights reserved.
//

#import "LianXianContainerView.h"
#import "LianXianComponentsView.h"
#import "LianxianDrawView.h"
#import "LianXianModel.h"@implementation LianXianContainerView- (id)initWithFrame:(CGRect)frame
{if (self = [super initWithFrame:frame]) {[self setup];}return self;
}- (void)setup{self.lianXianView = [[LianxianDrawView alloc]initWithFrame:self.bounds];self.componentsView = [[LianXianComponentsView alloc] initWithFrame:self.bounds];[self addSubview:self.lianXianView];[self addSubview:self.componentsView];
}@end
View Code

?

(7)顯示連線

//
//  ViewController.m
//  LianxianDemo
//
//  Created by tianjing on 15/3/31.
//  Copyright ? 2015年 tianjing. All rights reserved.
//

#import "ViewController.h"#import "LianXianContainerView.h"
#import "LianXianFrameUitity.h"
#import "LianXianModel.h"
#import "LianXianHeader.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];UIButton *clearBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 100, 40)];clearBtn.backgroundColor = [UIColor greenColor];[clearBtn setTitle:@"重置" forState:UIControlStateNormal];[clearBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];[clearBtn addTarget:self action:@selector(clear:) forControlEvents:UIControlEventTouchUpInside];//創建模型LianXianModel *lianxianModel = [[LianXianModel alloc] init];lianxianModel.questions = @[@"",@"",@""]; /// 左邊選項lianxianModel.options = @[@"",@"",@""];   /// 右邊選項//lianxianModel.relationships = @[@"天-世",@"好-夏",@"人-鋒"]; /// 連線關系,如果不為空,就只顯示,不能編輯//clearBtn.hidden = (lianxianModel.relationships.count>0);//連線視圖CGRect frame = [LianXianFrameUitity calculateSizeWithModel:lianxianModel];LianXianContainerView *containerView = [[LianXianContainerView alloc] initWithFrame:frame];containerView.center = self.view.center;containerView.componentsView.lianxianModel = lianxianModel;[self.view addSubview:containerView];[self.view addSubview:clearBtn];
}- (void)clear:(UIButton *)sender{[[NSNotificationCenter defaultCenter] postNotificationName:kClearAllLineNotification object:nil];
}@end
View Code

?

四、效果

提示:

左邊按鈕每次只有一個處于可連狀態,而且每一次連接完會循環自動下移。

右邊所有按鈕始終處于可連狀態。

同一個按鈕再一次連接新的連線后,之前舊的跟其相關的連線都會被取消。?

?

??

?

五、采坑

如果練習題的界面是放在cell中的,因為復用的問題,在發送起點和終點的通知時,要對通知做唯一標識處理。

如果不這么做,可能會出現的bug是:上一道做過的連線題的連線會出現在下一道還沒有做過的連線題上。

?

轉載于:https://www.cnblogs.com/XYQ-208910/p/8532379.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/250865.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/250865.shtml
英文地址,請注明出處:http://en.pswp.cn/news/250865.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

18 Context與組合的應用場景與使用問題

contextType 指定context類型為創建的上下文&#xff0c;此時不需要用Consumer組件包裹&#xff0c;使用this.context即可訪問會向上找最近的上下文并取值最適合的場景&#xff1a;雜亂無章的組件都需要同一些數據&#xff1b;若單純為了不層層傳遞屬性&#xff0c;使用contex…

http --- 共享加密(對稱加密)的幾個概念

使用互聯網進行數據傳輸時,可能會產生以下四個問題: 1. 竊聽: A向B發送的消息,有可能在傳輸過程中被X竊聽到 2. 假冒: A收到來自B的消息有可能是X冒充的 3. 篡改: A確實收到來自B的消息,但是該消息有可能被X篡改了 4. 事后否認:B確實收到了來自A的消息,但是A是惡意用戶,當A像B…

213. House Robber II 首尾相同的偷竊問題

&#xff3b;抄題&#xff3d;&#xff1a; You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of…

原型鏈

<!DOCTYPE html><html><head lang"en"> <meta charset"UTF-8"> <title></title></head><body><script> /* 原型中的默認屬性 原型鏈&#xff1a;當調用構造函數&#xff08;Fn()&a…

http --- 公開密鑰加密(非對稱加密)的幾個概念

公開密鑰加密: 公鑰加密,私鑰解密 公開密鑰加密的處理流程: 1. A準備通過互聯網向B發送數據 2. B生成公鑰P和私鑰S 3. B將P發送給A 4. A使用P進行加密,并將密文通過互聯網發送給B 5. B使用S進行解密得到數據公鑰加密的更具體的栗子: 1.B首先準備好公鑰P和私鑰S 2.B將公鑰發布…

19、20 Context API

安裝React Dev Tool Context對象.displayName 使用別名 不使用別名 React.createContext 創建指定的Context對象組件會找離自己最近的Provider&#xff0c;獲取其value變量名都叫value的情況&#xff0c;就近取AContext變量名有所區分&#xff0c;兩個value都可以獲取可以…

01-spring配置詳解

1 bean元素 <!--將User對象交給spring容器進行管理 --><!-- Bean元素:使用該元素描述需要spring容器管理的對象class屬性:被管理對象的完整類名.name屬性:給被管理的對象起個名字.獲得對象時根據該名稱獲得對象. 可以重復.可以使用特殊字符.id屬性: 與name屬性一模一…

第八模塊:算法設計模式、企業應用 第2章 企業應用工具學習

第八模塊&#xff1a;算法&設計模式、企業應用 第2章 企業應用工具學習轉載于:https://www.cnblogs.com/tqtl911/p/9131614.html

http --- 混合加密的具體過程

混合加密: 共享加密存在一個“共享密鑰”無法安全告知服務端的問題.公開加密存在,加密、解密速度慢的問題.混合加密則同時使用了2種加密技術,具體過程如下: 1. B提前生成公鑰P和私鑰S,并將P發布到網上 2. A想(通過互聯網)像B發送數據 3. A從互聯網上獲取B的公鑰P,并使用P對共享…

Vite+Vue3頁面空白、圖標不顯示問題解決

頁面空白問題 由于項目部署在子文件夾下&#xff0c;因此需要配置vite.config.js const config {base: ./, }el-icon圖標不顯示、打包時mkdir無權限 在控制臺Network看字體圖標的請求&#xff0c;發現地址多了_assets&#xff0c;本以為需要重新配置publicDir&#xff0c;后…

在HTML打開已安裝的App,未安裝跳轉到對應的下載鏈接

借鑒 HTML中判斷手機是否安裝某APP&#xff0c;跳轉或下載該應用 function lookApp () {var ua navigator.userAgentvar isAndroid /(Android);?[\s/]([\d.])?/.test(ua)var isIpad /(iPad).*OS\s([\d_])/.test(ua)var isIpod /(iPod)(.*OS\s([\d_]))?/.test(ua)var is…

javascript --- 自定義數組的反序函數

想寫一個自定義的_reverse函數,其作用是將傳入的數組進行部分反序. 效果如下: 輸入[1,2,3,4,5,6,7,8,9] 第一個將2~4個位置的數字反序 第二個將2~6個位置的數字反序. // js function _reverse(arr, s, e) {arr arr.join().slice(0,s) arr.join().slice(s,e).split().revers…

21 Fragment和短語法應用

React.Fragment jsx語法&#xff0c;相當于document.createDocumentFragment()創建文檔碎片容器&#xff0c;優化渲染解決了沒有根節點的問題<></>這種短語法也會聲明React.Fragment但短語法不支持keyReact.Fragment只支持key屬性&#xff0c;其余屬性如事件等不支…

201521123004《軟件工程》個人閱讀作業1

task1Task2: 201521123004 林藝如 博客&#xff1a;https://www.cnblogs.com/dabaolyr/ 碼云&#xff1a;https://gitee.com/dabao_lyr Task3&#xff1a;完成博客-閱讀與思考 閱讀參考材料&#xff0c;并回答下面幾個問題&#xff1a; &#xff08;1&#xff09;回想一下你初入…

在sql當中為了讓數據做緩存做with as的操作

今天看別人的代碼&#xff0c;突然發現之前理解的sql的with as的用法有新的理解。 之前理解的with as只是想著做單表的union all 操作時才使用&#xff0c;今天發現在可以使用逗號做分割&#xff0c;做緩存不同的表數據。 下面的例子如下&#xff1a; WITH t1 AS (SELECT file_…

javascript --- 從數組中,找出比給定元素大一丁點的元素

目標如下: 從數組[1,3,2,4,5,6,7]中找到比第1個位置大一丁點的元素 function _findIndex(arr, j){let k -1;let key arr[j];for(let i j; i< arr.length; i) {if(arr[i] > key) {if( k ! -1){if(arr[i] < arr[k]) {k i;}} else {k i;}}}return k } let arr [1,…

22 React高階組件

搭建服務端 yarn add express yarn add nodemon 在server目錄下 npm init -y // 增加dev腳本"scripts": {"dev": "nodemon ./index.js"},引入 git HOC High Order Component 高階組件&#xff0c;是組件的抽象HOC不是React提供的API&#xf…

PAT (Advanced Level) 1140~1143:1140模擬 1141模擬 1142暴力 1143 BST+LCA

1140 Look-and-say Sequence&#xff08;20 分&#xff09; 題意&#xff1a;觀察序列D, D1, D111, D113, D11231, D112213111, ...&#xff0c;顯然后一個串是對前一個串每一小段連續相同的字母及其個數的描述。例如&#xff0c;D112213111是對D11231的描述&#xff0c;原因是…

AngularJS:表達式

ylbtech-AngularJS&#xff1a;表達式1.返回頂部 1、AngularJS 表達式 AngularJS 使用 表達式 把數據綁定到 HTML。 AngularJS 表達式 AngularJS 表達式寫在雙大括號內&#xff1a;{{ expression }}。 AngularJS 表達式把數據綁定到 HTML&#xff0c;這與 ng-bind 指令有異曲同…

23 Refs的應用場景與選用思考

Refs含義 允許訪問真實DOMReact數據流&#xff1a;通過props來實現父子組件的交互Refs允許強制修改子組件 // 1. 構造器離添加實例屬性 this.ref React.createRef() // 2. 組件上綁定ref ref{this.ref} // 3. 使用&#xff1a;this.ref.currentinput class MyInput extends…