日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ios 第三方键盘开发 无限刷屏浅析

發布時間:2023/12/31 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios 第三方键盘开发 无限刷屏浅析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

姬拉 關注

0.1 2016.09.02 19:26* 字數 629 閱讀 958評論 2喜歡 4

故事前景:

? 某直播刷人氣,主播隨機截圖抽取當前留言者為中獎對象......

?想著寫個第三方鍵盤無限刷 ?然后寫了這個么小玩意,貼出來互相學習

首先當然是創建一個手機APP項目:(這一步貼上來真是浪費流量.....)

?

新建項目以后我直接新建了兩個控件:(為了研究鍵盤的發送,和寫入數據用)

?

?

一開始我以為蘋果會直接提供發送方法,類似點擊鍵盤上的(done,return....)找了一圈蘋果文檔么發現,后來去墻外發現了原來是換一種方式玩的,往下看:

在原來的項目上添加了一個 target 如圖 (這玩意就是蘋果的第三方鍵盤了)

?

?

如下是自動創建的兩個類,所有內容都從這里面展開:

?

首先要解決的第一個問題是 如何插入文字,以微信為例,如何在微信聊天輸入框插入文本:

UITextDocumentProxy 這個類為我們提供了插入,刪除,等基本操作,但是方法也不多就幾個基本的

//自己猜

- (void)dismissKeyboard;

//切換鍵盤

- (void)advanceToNextInputMode;

//判斷是否存在文本(我猜的沒有試驗)

- (BOOL)hasText;

//插入文本

- (void)insertText:(NSString*)text;

//刪除(我估計刪除一個字符,我猜的沒試)

- (void)deleteBackward;

?

這些方法夠用了,一開始跑起來時候默認是長這樣的:

?

?

創建新的view 沒有什么特別的

?

跑起來的時候讓我選擇個APP 執行 但是我發現 沒有選的也可以使用鍵盤,這個我后期研究差不多了陸續提交:

?

最最最重點的是 我們已經可以插入文字,接下來就是解決如何調用發送這個功能了,找了一圈文檔沒找到,后來聽了一遍 《流川楓與蒼井空》豁然開朗,原來只要插入 @“\n” 就能調用 別人APP的

-(BOOL)textFieldShouldReturn:(UITextField*)textField

這個方法。

//發送

[self.textDocumentProxyinsertText:@"\n"];

?

接下來的刷屏就簡單了,一個定時 一插一發 ?一發一插.....無窮盡也。

配上幾個效果圖:

?

?

end;

本人 課余喜歡研究? object pascal ,object c ,java,玩些 c# 。歡迎廣大IT男加群 (367276878)互相學習

大家好我叫姬拉

?

iOS 自定義第三方鍵盤

28畫生 關注

2017.05.03 15:56* 字數 434 閱讀 1099評論 4喜歡 1

iOS8新特性擴展(Extension)應用之四——自定義鍵盤控件

iOS8系統的開放第三方鍵盤,使得用戶在輸入法的選擇上更加自主靈活,也更加貼近不同語言的輸入風格。這篇博客,將介紹如何開發一個第三方的鍵盤控件。

一、了解UIInputViewController

UIInputViewController是系統擴展支持鍵盤擴展的一個類,通過這個類,我們可以自定義一款我們自己的鍵盤提供給系統使用。

首先,我們先來看一下這個類中的一些屬性和方法:

@property (nonatomic, retain) UIInputView *inputView;

鍵盤的輸入視圖,我們可以自定義這個視圖。

@property (nonatomic, readonly) NSObject <UITextDocumentProxy> *textDocumentProxy;

實現了UITextDocumentProxy協議的一個對象,后面會介紹這個協議。

@property (nonatomic, copy) NSString *primaryLanguage;

系統為我們準備了一些本地化的語言字符串

- (void)dismissKeyboard;

收鍵盤的方法

- (void)advanceToNextInputMode;

切換到下一輸入法的方法

UITextDocumentProxy協議內容如下:

?

@protocol UITextDocumentProxy <UIKeyInput>

//輸入的上一個字符

@property (nonatomic, readonly) NSString *documentContextBeforeInput;

//即將輸入的一個字符

@property (nonatomic, readonly) NSString *documentContextAfterInput;

//將輸入的字符移動到某一位置

- (void)adjustTextPositionByCharacterOffset:(NSInteger)offset;

?

@end

而UITextDocumentProxy這個協議繼承與UIKeyInput協議,UIKeyInput協議中提供的兩個方法用于輸入字符和刪除字符:

- (void)insertText:(NSString *)text;

- (void)deleteBackward;

二、創建一款最簡單的數字輸入鍵盤

? ? 創建一個項目,作為宿主APP,接著我們File->new->target->customKeyBoard:

?

Snip20170503_8.png

?

Snip20170503_9.png

系統要求我們對鍵盤的布局要使用autolayout,并且只可以采用代碼布局的方式,我們這里為了簡單演示,將坐標寫死:

- (void)viewDidLoad {

? ? [super viewDidLoad];

?? ?

? ? // 設置數字鍵盤的UI

? ? //數字按鈕布局

? ? for (int i=0; i<10; i++) {

? ? ? ? UIButton * btn = [UIButton buttonWithType:UIButtonTypeSystem];

? ? ? ? btn.frame=CGRectMake(20+45*(i%3), 20+45*(i/3), 40, 40);

? ? ? ? btn.backgroundColor=[UIColor greenColor];

? ? ? ? [btn setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];

? ? ? ? btn.tag=101+i;

? ? ? ? [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

? ? ? ? [self.view addSubview:btn];

? ? }

? ? //創建切換鍵盤按鈕

? ? UIButton * change = [UIButton buttonWithType:UIButtonTypeSystem];

? ? change.frame=CGRectMake(200,20, 80, 40) ;

? ? NSLog(@"%f,%f",self.view.frame.size.height,self.view.frame.size.width);

? ? [change setBackgroundColor:[UIColor blueColor]];

? ? [change setTitle:@"切換鍵盤" forState:UIControlStateNormal];

? ? [change addTarget:self action:@selector(change) forControlEvents:UIControlEventTouchUpInside];

? ? [self.view addSubview:change];

? ? //創建刪除按鈕

? ? UIButton * delete = [UIButton buttonWithType:UIButtonTypeSystem];

? ? delete.frame=CGRectMake(200, 120, 80, 40);

? ? [delete setTitle:@"delete" forState:UIControlStateNormal];

? ? [delete setBackgroundColor:[UIColor redColor]];

? ? [delete addTarget:self action:@selector(delete) forControlEvents:UIControlEventTouchUpInside];

? ? [self.view addSubview:delete];

}

//刪除方法

-(void)delete{

? ? if (self.textDocumentProxy.documentContextBeforeInput) {

? ? ? ? [self.textDocumentProxy deleteBackward];

? ? }

}

//切換鍵盤方法

-(void)change{

? ? [self advanceToNextInputMode];

}

//點擊數字按鈕 將相應數字輸入

-(void)click:(UIButton *)btn{

? ? [self.textDocumentProxy insertText:[NSString stringWithFormat:@"%ld",btn.tag-101]];

}

運行后,在使用之前,我們需要先加入這個鍵盤:在模擬器系統設置中general->keyboard->keyboards->addNowKeyboard

選中我們自定義的鍵盤,之后運行瀏覽器,切換到我們的鍵盤,效果如下:

?

?

//

//? KeyboardViewController.m

//? KeyboardViewController

//

//? Created by 王彥平 on 2019/2/18.

//? Copyright ? 2019年 王彥平. All rights reserved.

//

?

#import "KeyboardViewController.h"

?

@interface KeyboardViewController (){

? ? UIButton *godoit;

}

@property (nonatomic, strong) UIButton *nextKeyboardButton;

@end

?

@implementation KeyboardViewController

?

- (void)updateViewConstraints {

? ? [super updateViewConstraints];

?? ?

? ? // Add custom view sizing constraints here

}

?

- (void)viewDidLoad {

? ? [super viewDidLoad];

?? ?

? ? // Perform custom UI setup here

? ? self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem];

?? ?

? ? [self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal];

? ? [self.nextKeyboardButton sizeToFit];

? ? self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = NO;

?? ?

? ? [self.nextKeyboardButton addTarget:self action:@selector(handleInputModeListFromView:withEvent:) forControlEvents:UIControlEventAllTouchEvents];

?? ?

? ? [self.view addSubview:self.nextKeyboardButton];

?? ?

? ? [self.nextKeyboardButton.leftAnchor constraintEqualToAnchor:self.view.leftAnchor].active = YES;

? ? [self.nextKeyboardButton.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;

?

?? ?

? ? [self createuI];

}

?

- (void)textWillChange:(id<UITextInput>)textInput {

? ? // The app is about to change the document's contents. Perform any preparation here.

}

?

- (void)textDidChange:(id<UITextInput>)textInput {

? ? // The app has just changed the document's contents, the document context has been updated.

?? ?

? ? UIColor *textColor = nil;

? ? if (self.textDocumentProxy.keyboardAppearance == UIKeyboardAppearanceDark) {

? ? ? ? textColor = [UIColor whiteColor];

? ? } else {

? ? ? ? textColor = [UIColor blackColor];

? ? }

? ? [self.nextKeyboardButton setTitleColor:textColor forState:UIControlStateNormal];

}

-(void)createuI{

? ? godoit = [UIButton buttonWithType:UIButtonTypeCustom];

? ? godoit.backgroundColor = [UIColor blueColor];

? ? godoit.frame = CGRectMake(60, 100, 100, 100);

? ? [godoit setTitle:@"走你" forState:UIControlStateNormal];

? ? [godoit setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

? ? [godoit addTarget:self action:@selector(doit:) forControlEvents:UIControlEventTouchUpInside];

? ? [self.view addSubview:godoit];

?? ?

? ? UIButton *btn2? = [UIButton buttonWithType:UIButtonTypeCustom];

? ? btn2.backgroundColor = [UIColor blueColor];

? ? btn2.frame = CGRectMake(200, 100, 100, 100);

? ? [btn2 setTitle:@"變態循環" forState:UIControlStateNormal];

? ? [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

//? ? [btn2 addTarget:self action:@selector(send:) forControlEvents:UIControlEventTouchUpInside];

? ? [self.view addSubview:btn2];

?? ?

?

}

-(void)doit:(UIButton *)sender{

? ? [self.textDocumentProxy insertText:@"\n"];

?

? ? [self.textDocumentProxy insertText:@"你好我叫基拉"];

}

?

@end

?

#import "ViewController.h"

?

@interface ViewController ()<UITextViewDelegate,UITextFieldDelegate>

?

@end

?

@implementation ViewController

?

- (void)viewDidLoad {

? ? [super viewDidLoad];

? ? UITextView *text = [[UITextView alloc]initWithFrame:CGRectMake(0, 340, self.view.bounds.size.width, 300)];

? ? text.backgroundColor = [UIColor colorWithRed:0.8304 green:0.8304 blue:0.8304 alpha:1.0];

? ? [self.view addSubview:text];

? ? text.delegate = self;

?? ?

? ? UITextField *text2 = [[UITextField alloc]initWithFrame:CGRectMake(0, 30, self.view.bounds.size.width, 30)];

? ? text2.backgroundColor = [UIColor colorWithRed:0.8304 green:0.8304 blue:0.8304 alpha:1.0];

? ? [self.view addSubview:text2];

? ? text2.delegate = self;

}

?

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

? ? textField.text = [textField.text stringByAppendingString:@"done"];

? ? //發送

?? ?

? ? return YES;

}

-(void)textViewDidChange:(UITextView *)textView{

? ? textView.text = [textView.text stringByAppendingString:@""];

}

@end

?

#import "KeyboardViewController.h"

?

@interface KeyboardViewController (){

? ? UIButton *godoit;

}

?

@property (nonatomic, strong) UIButton *nextKeyboardButton;

@end

?

@implementation KeyboardViewController

?

- (void)updateViewConstraints {

? ? [super updateViewConstraints];

?? ?

? ? // Add custom view sizing constraints here

}

?

- (void)viewDidLoad {

? ? [super viewDidLoad];

?? ?

? ? // Perform custom UI setup here

? ? self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem];

?? ?

? ? [self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal];

? ? [self.nextKeyboardButton sizeToFit];

? ? self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = NO;

?? ?

? ? [self.nextKeyboardButton addTarget:self action:@selector(handleInputModeListFromView:withEvent:) forControlEvents:UIControlEventAllTouchEvents];

?? ?

? ? [self.view addSubview:self.nextKeyboardButton];

?? ?

? ? [self.nextKeyboardButton.leftAnchor constraintEqualToAnchor:self.view.leftAnchor].active = YES;

? ? [self.nextKeyboardButton.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;

? ? [self createuI];

?

}

?

- (void)textWillChange:(id<UITextInput>)textInput {

? ? // The app is about to change the document's contents. Perform any preparation here.

}

?

- (void)textDidChange:(id<UITextInput>)textInput {

? ? // The app has just changed the document's contents, the document context has been updated.

?? ?

? ? UIColor *textColor = nil;

? ? if (self.textDocumentProxy.keyboardAppearance == UIKeyboardAppearanceDark) {

? ? ? ? textColor = [UIColor whiteColor];

? ? } else {

? ? ? ? textColor = [UIColor blackColor];

? ? }

? ? [self.nextKeyboardButton setTitleColor:textColor forState:UIControlStateNormal];

}

-(void)createuI{

? ? godoit = [UIButton buttonWithType:UIButtonTypeCustom];

? ? godoit.backgroundColor = [UIColor blueColor];

? ? godoit.frame = CGRectMake(60, 100, 100, 100);

? ? [godoit setTitle:@"走你" forState:UIControlStateNormal];

? ? [godoit setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

? ? [godoit addTarget:self action:@selector(doit:) forControlEvents:UIControlEventTouchUpInside];

? ? [self.view addSubview:godoit];

?? ?

? ? UIButton *btn2? = [UIButton buttonWithType:UIButtonTypeCustom];

? ? btn2.backgroundColor = [UIColor blueColor];

? ? btn2.frame = CGRectMake(200, 100, 100, 100);

? ? [btn2 setTitle:@"變態循環" forState:UIControlStateNormal];

? ? [btn2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

? ? [btn2 addTarget:self action:@selector(send:) forControlEvents:UIControlEventTouchUpInside];

? ? [self.view addSubview:btn2];

?? ?

?? ?

}

-(void)doit:(UIButton *)sender{

? ? [self.textDocumentProxy insertText:@"\n"];

?? ?

? ? [self.textDocumentProxy insertText:@"你好我叫基拉"];

}

?

-(void)send:(UIButton *)sender{

? ? [self.textDocumentProxy insertText:@"\n"];

?

}

@end

?

?

?

總結

以上是生活随笔為你收集整理的ios 第三方键盘开发 无限刷屏浅析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久久久久久久久久综合 | 色老太hd老太色hd | 欧美激情视频在线观看 | 久久久国产精品无码 | julia一区二区三区中文字幕 | 亚洲中文字幕无码一区 | 亚洲88av | jizz日韩| 97se亚洲 | 国内少妇精品 | 国产第一页精品 | 在线精品免费视频 | 国产亚洲精品美女久久久久 | 国产欧美精品一区二区在线播放 | 高清久久久久久 | 国产乱码一区二区三区在线观看 | 日韩欧美中文字幕一区二区三区 | 久久久69 | 另类专区欧美 | 中文字幕一区二区三区乱码在线 | 蜜臀久久 | 国产 日韩 欧美 精品 | 国产精品欧美综合 | 国偷自产视频一区二区久 | 成人免费看片' | 欧美日韩成人一区二区三区 | 一区三区在线观看 | 麻豆高清 | 一区二区三区在线电影 | 日韩欧美中 | 欧美嘿咻视频 | 中文字幕视频在线 | 中国特级黄色片 | 国产欧美亚洲精品 | 91麻豆国产视频 | 黄色一级片在线看 | 日韩一区二区三区网站 | 免费亚洲一区二区 | 亚洲一区二区三区成人 | 麻豆av电影网| 欧美精品一区在线发布 | 国产成人精品免费网站 | 西西人体做爰大胆gogo | 91精品又粗又猛又爽 | 成人羞羞网站 | 91成品人影院| 国产高清视频在线播放 | 国产中文字幕久久 | 精品人妻一区二区三区日产乱码 | 国产无遮挡又黄又爽在线观看 | 一级全黄裸体免费观看视频 | japan粗暴video蹂躏 | 自拍视频网址 | 欧美一区二区三区婷婷 | 红桃成人网 | 亚洲一区二区三区四区不卡 | 免费成人一级片 | 123超碰| 色香蕉在线 | 久久思| 国产精品一区二区在线观看 | 毛片网在线观看 | 色婷婷在线观看视频 | 中文字幕日韩精品一区 | 99热中文 | 成人羞羞国产免费 | 国产色视频| 欧美日韩精品在线播放 | 国产第四页 | 黄色国产在线视频 | jizzjizz日本免费视频 | 成人a在线| 亚洲av久久久噜噜噜熟女软件 | 亚洲精品一区三区三区在线观看 | 日韩有码中文字幕在线观看 | 91国产在线免费观看 | 男女性杂交内射妇女bbwxz | 久久久高清免费视频 | 欧美三级精品 | 人妻丰满熟妇无码区免费 | 欧美一区二区三区免费看 | 天天爽夜夜爽夜夜爽精品 | 男人把女人捅爽 | 秋霞影院午夜丰满少妇在线视频 | 婷婷五月情 | 国产青青操 | 欧美成人免费在线视频 | 亚洲国产精品99 | 久久久无码精品亚洲国产 | 冲田杏梨 在线 | 完全免费在线视频 | 欧美在线免费视频 | 欧美亚日韩 | 国产内射一区 | 探花av在线| 国产精品成人一区二区三区 | 日韩国产一区二区三区 | 99精品福利视频 | 欧美无专区 |