IOS Analog terminal controls

Source: Internet
Author: User
<span id="Label3"></p><p class="p1"><p class="p1"><span class="s1">Aksdeviceconsole</span></p></p><p class="p1"><p class="p1"><span class="s1">AKSDeviceConsole.h</span></p></p><pre><pre><span style="color: #0000ff;">#import</span> <Foundation/Foundation.h><span style="color: #008000;"></span>/* * *<span style="color: #008000;"> Print Log control *</span>*/<span style="color: #008000;"></span><span style="color: #0000ff;">@interface </span> <span style="color: #000000;">aksdeviceconsole:nsobject</span>+ (<span style="color: #0000ff;">void</span><span style="color: #000000;">) startservice;</span> <span style="color: #0000ff;">@end</span></pre></pre><p><p></p></p><p><p>Aksdeviceconsole.m</p></p><pre><span style="color: #0000ff;"><span style="color: #0000ff;">#import</span></span> <span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">AKSDeviceConsole.h</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">#import</span></span> <span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">AppDelegate.h</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">#import</span></span><QuartzCore/QuartzCore.h><span style="color: #0000ff;"><span style="color: #0000ff;">#define</span></span>Aks_log_file_path [[aksdeviceconsole documentsdirectory] stringbyappendingpathcomponent:@ "ns.log"]<span style="color: #0000ff;"><span style="color: #0000ff;">#define</span></span>Appdelegate ((appdelegate *) [[uiapplication sharedapplication] delegate])<span style="color: #0000ff;"><span style="color: #0000ff;">@interface</span></span><span style="color: #000000;"><span style="color: #000000;">aksdeviceconsole () {uitextview</span></span>*<span style="color: #000000;"><span style="color: #000000;">textView;}</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">@end</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">@implementation</span></span><span style="color: #000000;"><span style="color: #000000;">Aksdeviceconsole</span></span>+ (<span style="color: #0000ff;"><span style="color: #0000ff;">ID</span></span><span style="color: #000000;"><span style="color: #000000;">) sharedinstance {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Static</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">ID</span></span><span style="color: #000000;"><span style="color: #000000;">__sharedinstance; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Static</span></span><span style="color: #000000;"><span style="color: #000000;">dispatch_once_t oncetoken; Dispatch_once (</span></span>&oncetoken, ^<span style="color: #000000;"><span style="color: #000000;">{__sharedinstance</span></span>=<span style="color: #000000;"><span style="color: #000000;">[[aksdeviceconsole alloc]init]; }); </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">__sharedinstance;}</span></span>+ (nsmutablestring *<span style="color: #000000;"><span style="color: #000000;">) Documentsdirectory {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span>[nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, YES) objectatindex:<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">];}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">ID</span></span><span style="color: #000000;"><span style="color: #000000;">) init {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(self =<span style="color: #000000;"><span style="color: #000000;">[super Init]) {[self initialsetup]; } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;">self <span style="color: #000000;">;}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Initialsetup {[self resetlogdata]; [self addgesturerecogniser];}</span></span>+ (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) StartService {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Double</span></span>Delayinseconds =<span style="color: #800080;"><span style="color: #800080;">0.1</span></span><span style="color: #000000;"><span style="color: #000000;">; dispatch_time_t Poptime</span></span>= Dispatch_time (dispatch_time_now, (int64_t) (delayinseconds *<span style="color: #000000;"><span style="color: #000000;">nsec_per_sec)); Dispatch_after (poptime, dispatch_get_main_queue (),</span></span>^(<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) {[aksdeviceconsole sharedinstance]; });}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) resetlogdata {[nsfilemanager.defaultmanager Removeitematpath:aks_log_file_path error:nil]; Freopen ([aks_log_file_path filesystemrepresentation],</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">a</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, stderr);}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Addgesturerecogniser {uiswipegesturerecognizer</span></span>*recogniser =<span style="color: #000000;"><span style="color: #000000;">[[uiswipegesturerecognizer alloc]initwithtarget:self action: @selector (showconsole)]; [recogniser setdirection:uiswipegesturerecognizerdirectionright]; [appdelegate.window addgesturerecognizer:recogniser];}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Showconsole {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(textView = =<span style="color: #000000;"><span style="color: #000000;">Nil) {cgrect bounds</span></span>=<span style="color: #000000;"><span style="color: #000000;">[[uiscreen mainscreen] bounds]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">float</span></span>YG =<span style="color: #800080;"><span style="color: #800080;">80.0</span></span><span style="color: #000000;"><span style="color: #000000;">; CGRect Viewrecttextview</span></span>= CGRectMake (<span style="color: #800080;"><span style="color: #800080;">0</span></span>, yG, bounds.size.width, bounds.size.height-<span style="color: #000000;"><span style="color: #000000;">yG); TextView</span></span>=<span style="color: #000000;"><span style="color: #000000;">[[uitextview alloc]initwithframe:viewrecttextview]; [textView Setbackgroundcolor:[uicolor blackcolor]; [textView Setfont:[uifont systemfontofsize:</span></span><span style="color: #800080;"><span style="color: #800080;"></span> a</span><span style="color: #000000;"><span style="color: #000000;">]]; [textView seteditable:no]; [textView Settextcolor:[uicolor whitecolor]; [[textView layer]setopacity:</span></span><span style="color: #800080;"><span style="color: #800080;">0.8</span></span><span style="color: #000000;"><span style="color: #000000;">]; [appdelegate.window addsubview:textview]; [appdelegate.window bringsubviewtofront:textview]; Uiswipegesturerecognizer</span></span>*recogniser =<span style="color: #000000;"><span style="color: #000000;">[[uiswipegesturerecognizer alloc]initwithtarget:self action: @selector (hidewithanimation)]; [recogniser setdirection:uiswipegesturerecognizerdirectionleft]; [textView addgesturerecognizer:recogniser]; [self Movethisviewtowardslefttoright:textview duration:</span></span><span style="color: #800080;"><span style="color: #800080;">0.30</span></span><span style="color: #000000;"><span style="color: #000000;">]; [self setuptogetlogdata]; [self scrolltolast]; }}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) hidewithanimation {[self movethisviewtowardsleft:textview duration:</span></span><span style="color: #800080;"><span style="color: #800080;">0.30</span></span><span style="color: #000000;"><span style="color: #000000;">]; Dispatch_after (dispatch_time (dispatch_time_now,</span></span><span style="color: #800080;"><span style="color: #800080;">0.5</span></span>* nsec_per_sec), Dispatch_get_main_queue (), ^<span style="color: #000000;"><span style="color: #000000;">{[self hideconsole]; });}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Hideconsole {[textView removefromsuperview]; [nsnotificationcenter.defaultcenter removeobserver:self]; TextView</span></span>=<span style="color: #000000;"><span style="color: #000000;">nil;}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Scrolltolast {nsrange txtoutputrange; Txtoutputrange.location</span></span>=<span style="color: #000000;"><span style="color: #000000;">textView.text.length; Txtoutputrange.length</span></span>=<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">; Textview.editable</span></span>=<span style="color: #000000;"><span style="color: #000000;">YES; [textView scrollrangetovisible:txtoutputrange]; [textView setselectedrange:txtoutputrange]; Textview.editable</span></span>=<span style="color: #000000;"><span style="color: #000000;">NO;}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Setuptogetlogdata {nsfilehandle</span></span>*filehandle =<span style="color: #000000;"><span style="color: #000000;">[nsfilehandle filehandleforreadingatpath:aks_log_file_path]; [nsnotificationcenter.defaultcenter addobserver:self selector: @selector (getData:) name:</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">nsfilehandlereadcompletionnotification</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">Object</span></span><span style="color: #000000;"><span style="color: #000000;">: filehandle]; [filehandle readinbackgroundandnotify];}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) GetData: (nsnotification *<span style="color: #000000;"><span style="color: #000000;">) Notification {nsdata</span></span>*data =<span style="color: #000000;"><span style="color: #000000;">notification.userinfo[nsfilehandlenotificationdataitem]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(data.length) {nsstring</span></span>*<span style="color: #0000ff;"><span style="color: #0000ff;">string</span></span>=<span style="color: #000000;"><span style="color: #000000;">[nsstring.alloc Initwithdata:data encoding:nsutf8stringencoding]; Textview.editable</span></span>=<span style="color: #000000;"><span style="color: #000000;">YES; Textview.text</span></span>= [textview.text Stringbyappendingstring:<span style="color: #0000ff;"><span style="color: #0000ff;">string</span></span><span style="color: #000000;"><span style="color: #000000;">]; Textview.editable</span></span>=<span style="color: #000000;"><span style="color: #000000;">NO; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Double</span></span>Delayinseconds =<span style="color: #800080;"><span style="color: #800080;">0.1</span></span><span style="color: #000000;"><span style="color: #000000;">; dispatch_time_t Poptime</span></span>= Dispatch_time (dispatch_time_now, (int64_t) (delayinseconds *<span style="color: #000000;"><span style="color: #000000;">nsec_per_sec)); Dispatch_after (poptime, dispatch_get_main_queue (),</span></span>^(<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) {[self scrolltolast]; }); [notification.</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Object</span></span><span style="color: #000000;"><span style="color: #000000;">readinbackgroundandnotify]; } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{[self performselector: @selector (refreshlog:) withobject:notification afterdelay:</span></span><span style="color: #800080;"><span style="color: #800080;">0.1</span></span><span style="color: #000000;"><span style="color: #000000;">]; }}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) Refreshlog: (nsnotification *<span style="color: #000000;"><span style="color: #000000;">) Notification {[notification.</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Object</span></span><span style="color: #000000;"><span style="color: #000000;">readinbackgroundandnotify];}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) movethisviewtowardsleft: (UIView *) View Duration: (<span style="color: #0000ff;"><span style="color: #0000ff;">float</span></span><span style="color: #000000;"><span style="color: #000000;">) dur; {[UIView Animatewithduration:dur animations:</span></span>^<span style="color: #000000;"><span style="color: #000000;">{[view setframe:cgrectmake (view.frame.origin.x</span></span>-<span style="color: #000000;"><span style="color: #000000;">[[uiscreen mainscreen]bounds].size.width, view.frame.origin.y, view.frame.size.width, view.frame.size.height]]; } completion:</span></span>^<span style="color: #000000;"><span style="color: #000000;">(BOOL finished) {}];}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) movethisviewtowardslefttoright: (UIView *) View Duration: (<span style="color: #0000ff;"><span style="color: #0000ff;">float</span></span><span style="color: #000000;"><span style="color: #000000;">) dur; {cgrect Original</span></span>=<span style="color: #000000;"><span style="color: #000000;">[view frame]; [view Setframe:cgrectmake (view.frame.origin.x</span></span>-<span style="color: #000000;"><span style="color: #000000;">[[uiscreen mainscreen]bounds].size.width, view.frame.origin.y, view.frame.size.width, view.frame.size.height]]; [UIView Animatewithduration:dur animations:</span></span>^<span style="color: #000000;"><span style="color: #000000;">{[view setframe:original]; } completion:</span></span>^<span style="color: #000000;"><span style="color: #000000;">(BOOL finished) {}];}</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">@end</span></span></pre><p><p></p></p><p><p>IOS Analog terminal controls</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.