-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
595 lines (311 loc) · 44.9 KB
/
index.html
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>WangPangPang | be hangry be foolish</title>
<meta name="author" content="王琪">
<meta name="description" content="write I want to">
<meta name="keywords" content="ios">
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta property="og:site_name" content="WangPangPang"/>
<meta property="og:image" content="/favicon.ico"/>
<link href="/favicon.ico" rel="icon">
<link rel="alternate" href="/atom.xml" title="WangPangPang" type="application/atom+xml">
<link rel="stylesheet" href="/css/style.css" media="screen" type="text/css">
</head>
<body>
<div class="blog">
<div class="content">
<header>
<div class="site-branding">
<h1 class="site-title">
<a href="/">WangPangPang</a>
</h1>
<p class="site-description">be hangry be foolish</p>
</div>
<nav class="site-navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/archives">Archives</a></li>
</ul>
</nav>
</header>
<main class="site-main posts-loop">
<article>
<h3 class="article-title"><a href="/2018/09/19/开发记录/"><span>开发记录</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/09/19/开发记录/" rel="bookmark">
<time class="entry-date published" datetime="2018-09-19T02:08:11.000Z">
2018-09-19
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<h2 id="2018-9-19"><a href="#2018-9-19" class="headerlink" title="2018.9.19"></a>2018.9.19</h2><p>ijkplayer设置请求头:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">IJKFFOptions *options = [IJKFFOptions optionsByDefault];</span><br><span class="line"> [options setFormatOptionValue:@"Referer:www.juexiaotime.com" forKey:@"headers"];</span><br></pre></td></tr></table></figure></p>
<p> 多个headers用\r\n隔开</p>
<h2 id="2018-9-26"><a href="#2018-9-26" class="headerlink" title="2018.9.26"></a>2018.9.26</h2><p> injection3 开发界面调试工具:<br> 1、在我们的项目中- (BOOL)application:(UIApplication <em>)application didFinishLaunchingWithOptions:(NSDictionary </em>)launchOptions方法加入如下代码:<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"> if DEBUG</span><br><span class="line">// for iOS</span><br><span class="line">[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle"] load];</span><br><span class="line">// for tvOS</span><br><span class="line">[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/tvOSInjection.bundle"] load];</span><br><span class="line">// for masOS</span><br><span class="line">[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/macOSInjection.bundle"] load];</span><br><span class="line">endif</span><br></pre></td></tr></table></figure></p>
<p> 2、需要修改的文件里添加方法,输入代码后command+s改变UI<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"> -(void)injected{</span><br><span class="line">NSLog(@"I've been injected: %@", self);</span><br><span class="line">self.view.backgroundColor = [UIColor goldColor];</span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
<h2 id="2018-9-27"><a href="#2018-9-27" class="headerlink" title="2018.9.27"></a>2018.9.27</h2><p>修改textview的menuitem直接重写<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">//设置菜单 </span><br><span class="line">UIMenuItem *menuItem = [[UIMenuItem alloc]initWithTitle:@"响应菜单" action:@selector(selfMenu:)]; </span><br><span class="line">UIMenuController *menuController = [UIMenuController sharedMenuController]; </span><br><span class="line">[menuController setMenuItems:[NSArray arrayWithObject:menuItem]];</span><br><span class="line"></span><br><span class="line">-(BOOL)canPerformAction:(SEL)action withSender:(id)sender</span><br></pre></td></tr></table></figure></p>
<p>这个方法会继承系统默认的menuitem方法,必须继承textview,在textview的子类里重写上面的方法才行</p>
<h2 id="2018-10-7"><a href="#2018-10-7" class="headerlink" title="2018.10.7"></a>2018.10.7</h2><p>1、记一次蛋疼的bug,原生输入法再输入一次文字之后会自动添加很多乱码字符,打断点一句一句代码看过之后发现是在某个角落循环调用给textView赋值了,虽然修改起来很简单,但反应到前端的效果还是一脸懵逼的。<br>2、在输入框光标位置插入文字:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">NSMutableString *mutableString = self.textView.text.mutableCopy;</span><br><span class="line"> [mutableString insertString:resultFromJson atIndex:self.textView.selectedRange.location];</span><br><span class="line"> self.textView.text = mutableString;</span><br></pre></td></tr></table></figure></p>
<p>3、<code>NSIntersectionRange(<#NSRange range1#>, <#NSRange range2#>)</code>交集<br><code>NSUnionRange(<#NSRange range1#>, <#NSRange range2#>)</code>并集</p>
<h2 id="2018-10-10"><a href="#2018-10-10" class="headerlink" title="2018.10.10"></a>2018.10.10</h2><p>textview添加字数限制崩溃问题,添加一行代码<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">- (void)textFieldTextDidChanged:(UITextField *)sender</span><br><span class="line">{</span><br><span class="line"> NSString * tempString = sender.text;</span><br><span class="line"> </span><br><span class="line"> if (sender.markedTextRange == nil && tempString.length > kMaxLength)</span><br><span class="line"> {</span><br><span class="line"> sender.text = [tempString substringToIndex:kMaxLength];</span><br><span class="line"> [sender.undoManager removeAllActions];</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
<p>或者YY的处理方式:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {</span><br><span class="line"> </span><br><span class="line"> application.applicationSupportsShakeToEdit = NO;</span><br><span class="line"> </span><br><span class="line"> return YES;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<article>
<h3 class="article-title"><a href="/2018/07/20/UISearchController的坑/"><span>UISearchController的坑</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/07/20/UISearchController的坑/" rel="bookmark">
<time class="entry-date published" datetime="2018-07-20T02:45:00.000Z">
2018-07-20
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">//自定义的搜索结果controller</span><br><span class="line"> JXSearchResultController *resultVC = [[JXSearchResultController alloc]init];</span><br><span class="line"> resultVC.delegate = self;</span><br><span class="line"> //创建searchcontroller</span><br><span class="line"> UISearchController *searchVC = [[UISearchController alloc]initWithSearchResultsController:resultVC];</span><br><span class="line"> //隐藏导航栏</span><br><span class="line"> searchVC.hidesNavigationBarDuringPresentation = YES;</span><br><span class="line"> searchVC.searchBar.delegate = resultVC;</span><br><span class="line"> self.searchVC = searchVC;</span><br><span class="line"> //改变searchbar的背景色</span><br><span class="line"> searchVC.searchBar.barTintColor = White_Color;</span><br><span class="line"> //改变searchbar输入框背景色</span><br><span class="line"> UIView *searchTextField = [[[searchVC.searchBar.subviews firstObject]subviews]lastObject];</span><br><span class="line"> searchTextField.backgroundColor = Backgourd_Color;</span><br><span class="line"> //</span><br><span class="line"> [searchVC.searchBar sizeToFit];</span><br><span class="line"> //NO表示UISearchController在present时,可以覆盖当前controller。默认为NO</span><br><span class="line"> searchView = searchVC.searchBar;</span><br><span class="line"> [searchBgView addSubview:searchView];</span><br><span class="line"> </span><br><span class="line"> searchBgView.frame = CGRectMake(0, naviHeight, kMAINScreenWidth, searchVC.searchBar.height);</span><br><span class="line"> searchView.frame = searchView.bounds;</span><br><span class="line"> mainView.frame = CGRectMake(0, naviHeight + searchVC.searchBar.height, kMAINScreenWidth, kMAINScreenHeight - kTabNavHeight - kNavigationRealHeight);</span><br><span class="line"> //当前显示controller设为rootcontroller作为跳转使用</span><br><span class="line"> self.definesPresentationContext = YES;</span><br></pre></td></tr></table></figure>
<p>说他坑主要集中在获取他的height上,需要先sizetofit确定frame后获取height。<br>第二坑是searchVC.definesPresentationContext设为No后要手动把active设为no才能跳转<br>第三坑是改变背景色,这样方式比较暴力,在想没有更好的办法<br>第四坑是直接searchBgView=searchVC.searchBar无效,要在view上再加一层view,将他设为<br>searchVC.searchBar才有效。<br>第五坑搜索结果后push新页面时搜索结果页在最上面,需要设置self.definesPresentationContext = YES;<br>第六坑,搜索激活后,点击tabbar切换控制器 在点tabbar返回 发现searchVC被导航栏覆盖了,暂时解决方法,点击其他tabbar的时候active设为NO,并且要重置下searchVC.searchbar的frame,不然会错位,这也是个坑</p>
<p>为了要个UISearchController的动画效果,踩得坑还真是不少。</p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<article>
<h3 class="article-title"><a href="/2018/07/18/UITest/"><span>UITest</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/07/18/UITest/" rel="bookmark">
<time class="entry-date published" datetime="2018-07-18T06:46:42.000Z">
2018-07-18
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<p>运行程序,点击UITest.m, 点击红点开始录制你要的操作,然后运行测试代码看是否通过</p>
<p>录制过程中的一些代码报错的地方需要手动替换,Unicode编码要自己替换成汉字。</p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<article>
<h3 class="article-title"><a href="/2018/07/17/日历/"><span>日历</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/07/17/日历/" rel="bookmark">
<time class="entry-date published" datetime="2018-07-17T03:27:06.000Z">
2018-07-17
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<p>最近有个任务是写日历,记录一下遇到的坑,获取星期返回的数字,从星期日开始,星期六结束,对应数字1-7.</p>
<p>计算“yyyy-MM-dd”的时间戳是在当天0点,如果要获取这天结尾需要+1天。</p>
<p>遍历整个日历是直接遍历整个collectionview的indexpath,不要分区遍历,不然头尾衔接不上</p>
<p>关于合并两个相邻日期的详情文字,只有覆盖一层view,通过遍历整个collectionview的indexpath,获取需要遍历的indexpath,然后计算坐标,在到maskview上添加合并的文字,并取消collectionview里的文字。</p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<article>
<h3 class="article-title"><a href="/2018/07/16/遇到的坑/"><span>遇到的坑</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/07/16/遇到的坑/" rel="bookmark">
<time class="entry-date published" datetime="2018-07-16T05:49:30.000Z">
2018-07-16
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<p>在用AVPlayer和AVAduioPlayer时,遇到有一些音频获取的时长与真实时长有差异,而且这个bug只在iOS11以下存在,应该是苹果接口的问题</p>
<p>解决方案有两个<br>一、重新编码解码该音频<br>二、用流媒体播放器</p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<article>
<h3 class="article-title"><a href="/2018/05/31/编译ijkplayer遇到的坑/"><span>编译ijkplayer遇到的坑</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/05/31/编译ijkplayer遇到的坑/" rel="bookmark">
<time class="entry-date published" datetime="2018-05-31T00:46:25.000Z">
2018-05-31
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<p>如果要支持https的播放需要编译openssl这个文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"># 进入到刚刚新建的文件夹内 </span><br><span class="line">cd ~/Desktop/ijkplayer/ </span><br><span class="line"># 获取ijkplayer源码 </span><br><span class="line">git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-ios </span><br><span class="line"># 进入源码目录 </span><br><span class="line">cd ijkplayer-ios </span><br><span class="line"># 切换分支 (目前为k0.8.8, 可以自行去GitHub查看最新版本号) </span><br><span class="line">git checkout -B latest k0.8.8</span><br><span class="line"></span><br><span class="line">./init-ios.sh</span><br><span class="line">./init-openssl.sh</span><br><span class="line"></span><br><span class="line">cd ios </span><br><span class="line"># 在模块文件中添加一行配置 以启用 openssl 组件 </span><br><span class="line">echo 'export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-openssl"' >> ../config/module.sh ./compile-ffmpeg.sh clean</span><br><span class="line"></span><br><span class="line">./compile-openssl.sh all</span><br><span class="line"></span><br><span class="line"># 编译ffmpeg</span><br><span class="line">./compile-ffmpeg.sh all</span><br><span class="line"></span><br><span class="line">open IJKMediaPlayer/IJKMediaPlayer.xcodeproj</span><br><span class="line">#选择libcrypto.a和libssl.a加入库</span><br><span class="line">#在模拟器和真机分别编译</span><br><span class="line">#run模式切换为release</span><br><span class="line"></span><br><span class="line">#合并模拟器和真机的包</span><br><span class="line">lipo -create Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output IJKMediaFramework</span><br></pre></td></tr></table></figure>
<p>依赖库<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">1. libc++.tbd ( 编译器选 gcc 的请导入 libstdc++.tbd )</span><br><span class="line">2. libz.tbd</span><br><span class="line">3. libbz2.tbd</span><br><span class="line">4. AudioToolbox.framework</span><br><span class="line">5. UIKit.framework</span><br><span class="line">6. CoreGraphics.framework</span><br><span class="line">7. AVFoundation.framework</span><br><span class="line">8. CoreMedia.framework</span><br><span class="line">9. CoreVideo.framework</span><br><span class="line">10. MediaPlayer.framework</span><br><span class="line">11. MobileCoreServices.framework</span><br><span class="line">12. OpenGLES.framework</span><br><span class="line">13. QuartzCore.framework</span><br><span class="line">14. VideoToolbox.framework</span><br></pre></td></tr></table></figure></p>
<p>支持armv7 需要xcode7以下的编译,从官网下一个xcode7,让两个xcode并存,切换xcode<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo xcode-select -s /Applications/Xcode5.0.2/Xcode.app/Contents/Developer</span><br></pre></td></tr></table></figure></p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<article>
<h3 class="article-title"><a href="/2018/05/29/SVProgress替换默认图片/"><span>SVProgress替换默认图片</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/05/29/SVProgress替换默认图片/" rel="bookmark">
<time class="entry-date published" datetime="2018-05-29T07:45:55.000Z">
2018-05-29
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<p>美工给了个旋转图标,但是只有一张图,要在SVProgress里替换图片只有一个方法<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[SVProgressHUD showImage:image status:text];</span><br></pre></td></tr></table></figure></p>
<p>如果只放一张图他是不会动的,所以需要一个gif动图效果才行,所以我把那张图片顺时针旋转了一圈,然后按角度等比例截图成新图片,组成一个动图添加进<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[UIImage animatedImageWithImages:images duration:2];</span><br></pre></td></tr></table></figure></p>
<p>这样就相当于它是转起来了</p>
<p>截图代码,我是转一圈设置的2s,由于屏幕的刷新频率是60,所以生成了120张图,但是好像60张也感觉不出明显的卡顿。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">//将一张图片变成连续的动图</span><br><span class="line">+ (NSArray *)changeImageToArrayImage:(UIImage *)image {</span><br><span class="line"> NSMutableArray *images = [[NSMutableArray alloc]init];</span><br><span class="line"> </span><br><span class="line"> NSInteger count = 120;</span><br><span class="line"> for (int i = 0; i < count; i++) {</span><br><span class="line"> float angle = M_PI * 2 / count * i;</span><br><span class="line"> UIImage *newImage = [image imageByRotate:angle fitSize:NO];</span><br><span class="line"> [images addObject:newImage];</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> return images.copy;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<article>
<h3 class="article-title"><a href="/2018/05/28/YYTextView修改UIMenuController/"><span>YYTextView修改UIMenuController</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/05/28/YYTextView修改UIMenuController/" rel="bookmark">
<time class="entry-date published" datetime="2018-05-28T06:57:43.000Z">
2018-05-28
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<p>最新有一个新需求,要求用户把文章内容能加入到他的笔记里,但是不能复制外面,所以系统的复制粘贴功能要禁用,我就想到了用YYTextView来做选择复制的功能,但是他的功能没有自定义UIMenuController的接口,所以要改他的源码,所以稍微阅读了下YYTextView的源码,实现了自定义UIMenuController的功能。</p>
<p>第一步、在YYTextView.h文件里添加接口</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">//自定义menu菜单</span><br><span class="line">@property (nonatomic, strong) NSArray<UIMenuItem *> *menuItems;</span><br><span class="line">//隐藏菜单 这两个是他自己隐藏的接口,暴露出来,有地方会用到</span><br><span class="line">- (void)_hideMenu;</span><br><span class="line">- (void)_hideMagnifier;</span><br><span class="line">//禁止所有的menu菜单</span><br><span class="line">@property (nonatomic, assign) BOOL forbidMenu;</span><br></pre></td></tr></table></figure>
<p>第二步,在.m里添加实现<br>在_showMenu这个方法里</p>
<p>在初始化menu的地方添加</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">if (self.menuItems.count > 0) {</span><br><span class="line"> menu.menuItems = self.menuItems;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>在这个方法- (BOOL)canPerformAction:(SEL)action withSender:(id)sender里添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">if (self.forbidMenu == YES) {</span><br><span class="line"> return NO;</span><br><span class="line"> }</span><br><span class="line"> if (self.menuItems.count > 0) {</span><br><span class="line"> return NO;</span><br><span class="line"> }</span><br></pre></td></tr></table></figure></p>
<p>第三步,实现items</p>
<p>在你要用YYTextView的地方添加items</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">UIMenuItem *cancelItem = [[UIMenuItem alloc]initWithTitle:@"取消" action:@selector(cancelMenuItem:)];</span><br><span class="line"> UIMenuItem *addNoteItem = [[UIMenuItem alloc]initWithTitle:@"加入到笔记" action:@selector(addNoteMenuItem:)];</span><br><span class="line"> textview.menuItems = @[cancelItem,addNoteItem];</span><br></pre></td></tr></table></figure>
<p>同样重写</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {</span><br><span class="line"> if (action == @selector(cancelMenuItem:)) {</span><br><span class="line"> return YES;</span><br><span class="line"> } else if (action == @selector(addNoteMenuItem:)) {</span><br><span class="line"> return YES;</span><br><span class="line"> }</span><br><span class="line"> return NO;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>最后实现@selector(cancelMenuItem:) 和 @selector(addNoteMenuItem:) 方法就行了</p>
<p>效果:</p>
<p><img src="https://raw.githubusercontent.com/wqforever/wqforever.github.io/master/image/1527491847756.jpg" alt="Alt Text"></p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<article>
<h3 class="article-title"><a href="/2018/04/29/yycache的坑/"><span>yycache的坑</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/04/29/yycache的坑/" rel="bookmark">
<time class="entry-date published" datetime="2018-04-29T11:34:24.000Z">
2018-04-29
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<p>最近有个需求需要记录用过的viewcontroller,所以打算用yycache来缓存,然后发现缓存倒是缓存了,但是再取出来的viewcontroller的地址都变了,而且是每取一次变一次。</p>
<p>猜想是yycache在缓存或者取的时候做了一次copy操作,导致原来的地址变了,所以自己实现了一个简单的记录viewcontroller的方法</p>
<p>.h<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">#import <Foundation/Foundation.h></span><br><span class="line"></span><br><span class="line">@interface JXMemoryCache : NSObject</span><br><span class="line"></span><br><span class="line">+ (instancetype)shareManager;</span><br><span class="line"></span><br><span class="line">- (void)addObject:(id)object;</span><br><span class="line"></span><br><span class="line">- (id)getObject;</span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>.m<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">#import "JXMemoryCache.h"</span><br><span class="line"></span><br><span class="line">@interface JXMemoryCache()</span><br><span class="line">@property (nonatomic, strong) NSMutableArray *caches;</span><br><span class="line">@end</span><br><span class="line">@implementation JXMemoryCache</span><br><span class="line"></span><br><span class="line">+ (instancetype)shareManager {</span><br><span class="line"> static JXMemoryCache *cache = nil;</span><br><span class="line"> static dispatch_once_t onceToken;</span><br><span class="line"> dispatch_once(&onceToken, ^{</span><br><span class="line"> cache = [[JXMemoryCache alloc]init];</span><br><span class="line"> cache.caches = [[NSMutableArray alloc]init];</span><br><span class="line"> });</span><br><span class="line"> </span><br><span class="line"> return cache;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">- (void)addObject:(id)object {</span><br><span class="line"> JXMemoryCache *cache = [JXMemoryCache shareManager];</span><br><span class="line"> </span><br><span class="line"> [cache.caches addObject:object];</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">- (id)getObject {</span><br><span class="line"> JXMemoryCache *cache = [JXMemoryCache shareManager];</span><br><span class="line"> </span><br><span class="line"> return cache.caches;</span><br><span class="line">}</span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>扩展补全这个类 再说吧</p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<article>
<h3 class="article-title"><a href="/2018/04/14/自定义模板/"><span>自定义模板</span></a></h3>
<div class="article-top-meta">
<span class="posted-on">
<a href="/2018/04/14/自定义模板/" rel="bookmark">
<time class="entry-date published" datetime="2018-04-14T07:11:38.000Z">
2018-04-14
</time>
</a>
</span>
</div>
<div class="article-content">
<div class="entry">
<p>1.首先找到系统模板路径,我的是xcode9。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/应用程序/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source/Cocoa Touch Class.xctemplate</span><br></pre></td></tr></table></figure>
<p>目录如下:</p>
<p><img src="https://raw.githubusercontent.com/wqforever/wqforever.github.io/master/image/97033637-E8DB-43A6-8EF1-8150750DF240.png" alt="Alt Text"></p>
<p>2.然后按规则创建文件夹 名字+Objective-c,再创建两个文件,名字是<strong>FILEBASENAME</strong>.h,__FILEBASENAME.m</p>
<p><img src="https://raw.githubusercontent.com/wqforever/wqforever.github.io/master/image/DDEB0040-7E14-45AE-ADE6-89A81FE8B845.png" alt="Alt Text"></p>
<p>3.然后修改文件里面内容<br>.h<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">//</span><br><span class="line">// ___FILENAME___</span><br><span class="line">// ___PROJECTNAME___</span><br><span class="line">//</span><br><span class="line">// Created by ___FULLUSERNAME___ on ___DATE___.</span><br><span class="line">//___COPYRIGHT___</span><br><span class="line">//</span><br><span class="line"></span><br><span class="line">#import "JXBaseViewController.h"</span><br><span class="line"></span><br><span class="line">@interface ___FILEBASENAMEASIDENTIFIER___ : JXBaseViewController</span><br><span class="line"></span><br><span class="line">@property (nonatomic, copy) NSString *url;</span><br><span class="line"></span><br><span class="line">@property (nonatomic, strong) NSDictionary *params;</span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>.m<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br></pre></td><td class="code"><pre><span class="line">//</span><br><span class="line">// ___FILENAME___</span><br><span class="line">// ___PROJECTNAME___</span><br><span class="line">//</span><br><span class="line">// Created by ___FULLUSERNAME___ on ___DATE___.</span><br><span class="line">//___COPYRIGHT___</span><br><span class="line">//</span><br><span class="line"></span><br><span class="line">#import "___FILEBASENAME___.h"</span><br><span class="line"></span><br><span class="line">// Controllers</span><br><span class="line"></span><br><span class="line">// Model</span><br><span class="line"></span><br><span class="line">// Views</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">//#define <#macro#> <#value#></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">@interface ___FILEBASENAMEASIDENTIFIER___ ()</span><br><span class="line"></span><br><span class="line">//@property (nonatomic, strong) <#type#> *<#name#></span><br><span class="line"></span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation ___FILEBASENAMEASIDENTIFIER___</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#pragma mark - View Controller LifeCyle</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad</span><br><span class="line">{</span><br><span class="line"> [super viewDidLoad];</span><br><span class="line"> </span><br><span class="line"> [self initialNavigationBar];</span><br><span class="line"> [self initialUserInterface];</span><br><span class="line"> [self httpRequest];</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">- (void)viewDidAppear:(BOOL)animated</span><br><span class="line">{</span><br><span class="line"> [super viewDidAppear:animated];</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">- (void)viewWillDisappear:(BOOL)animated</span><br><span class="line">{</span><br><span class="line"> [super viewWillDisappear:animated];</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">#pragma mark - data</span><br><span class="line">- (void)httpRequest {</span><br><span class="line"> </span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">#pragma mark - ui</span><br><span class="line">- (void)initialUserInterface {</span><br><span class="line"> </span><br><span class="line">}</span><br><span class="line">#pragma mark - Initial Methods</span><br><span class="line"></span><br><span class="line">- (void)initialNavigationBar</span><br><span class="line">{</span><br><span class="line"> // self.navigationItem.title = <#title#>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">#pragma mark - Override</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#pragma mark - Target Methods</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#pragma mark - Notification Methods</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#pragma mark - KVO Methods</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#pragma mark - Privater Methods</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#pragma mark - Setter Getter Methods</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#pragma mark - dealloc</span><br><span class="line">- (void)didReceiveMemoryWarning</span><br><span class="line">{</span><br><span class="line"> [super didReceiveMemoryWarning];</span><br><span class="line"> </span><br><span class="line"> [[SDImageCache sharedImageCache] setValue:nil forKey:@"memCache"];</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">- (void)dealloc</span><br><span class="line">{</span><br><span class="line"> [[NSNotificationCenter defaultCenter] removeObserver:self];</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>4.修改TemplateInfo.plist里的值<br><img src="https://raw.githubusercontent.com/wqforever/wqforever.github.io/master/image/6466C6A5-1980-420B-8477-842E3079A70A.png" alt="Alt Text"></p>
<p><strong>踩下的坑:创建文件和修改plist先把文件复制到桌面创建修改好在替换里面的文件,直接修改里面的文件是不行的,即使把权限修改为读写也不行</strong></p>
<p>有啥问题联系我QQ597438567</p>
</div>
</div>
<div class="article-footer">
<div class="article-meta pull-left">
</div>
</div>
</article>
<nav class="pagination">
<a href="/page/2/" class="pagination-next">Next</a>
</nav>
</main>
<footer class="site-footer">
<p class="site-info">
Proudly powered by <a href="https://hexo.io/" target="_blank">Hexo</a> and
Theme by <a href="https://github.com/CodeDaraW/Hacker" target="_blank">Hacker</a>
</br>
© 2018 王琪
</p>
</footer>
</div>
</div>
</body>
</html>