知识积累

来源:互联网 发布:淘宝货源 编辑:程序博客网 时间:2024/06/10 16:42
1.返回整个屏幕边界 
Java代码  收藏代码
  1. [[UIScreen mainScreen] bounds];  


2.返回整个屏幕的可显示区域 
Java代码  收藏代码
  1. [[UIScreen mainScreen] applicationFrame];  


3.延迟调用自己的方法 
Java代码  收藏代码
  1. - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;  


4.定时器(每隔一定时间调用些方法) 
Java代码  收藏代码
  1. + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;  


5.隐藏任务栏 
Java代码  收藏代码
  1. [[UIApplication sharedApplication] setStatusBarHidden:YES];  


6.得到应用程序路径 
Java代码  收藏代码
  1. NSHomeDirectory()  


7.网络活动指示器 
Java代码  收藏代码
  1. [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];  



8.暂停一秒钟 
Java代码  收藏代码
  1. [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];  


9.设置标准VIEW角边为圆角 
Java代码  收藏代码
  1. 加入QuartzCore.frameworl  
  2. #import <QuartzCore/QuartzCore.h>  
  3. [webView.layer setCornerRadius:15.0f];  
  4. [webView.layer setMasksToBounds:YES];  


10.给UIView添加图片 
Java代码  收藏代码
  1. view.layer.contents = (id)[UIImage imageNamed:@"tc_pop_content_view.png"].CGImage;  


11.角度换算成弧度 
Java代码  收藏代码
  1. 公式 M * 3.14159 / 180  
  2. 例:M = 45度  
  3. 弧度值:大约0.7853  
  4. double radians(float degrees){  
  5.       return (degrees * 3.14159265) / 180.0;  
  6. }  


12.判断是否存在该类

Class musicClass = (NSClassFromString(@"MPMusicPlayerController"));

if (musicClass !=nil) {




13.

MFMailComposeViewController



14.用safari打开UIWebView里面的超链接

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    

    if (([[[request URL] scheme] isEqualToString: @"http"]  || 

         [[[request URL] scheme] isEqualToString: @"https"] || 

         [[[request URL] scheme] isEqualToString: @"mailto"])

        && (navigationType ==UIWebViewNavigationTypeLinkClicked)) {

        

        return ![[UIApplication sharedApplication] openURL:[request URL]];

    }    

   returnYES;

}



15.CALayer绘制减轻锯齿与动画质量

        self.bounds =CGRectInset([selfbounds],0.1,0.1);

        self.contentsScale =1;




16.清除cookie 

NSHTTPCookie *cookie;

       NSHTTPCookieStorage *storage = [NSHTTPCookieStoragesharedHTTPCookieStorage];

        for (cookie in [storage cookies]) {

            [storagedeleteCookie:cookie];

        }



17.锁屏后,继续发声。当设置为震动时,也能出声。

#import<AudioToolbox/AudioToolbox.h> 

[[UIApplicationsharedApplication]beginReceivingRemoteControlEvents];

[[AVAudioSession sharedInstance]setDelegate:self];

[[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlaybackerror:nil];

[[AVAudioSession sharedInstance]setActive:YESerror:nil];




18.播放系统提示音

//1

NSString *soundPath = [[NSBundlemainBundle]pathForResource:@"tishi"ofType:@"caf"];

NSURL *musicURL=[[NSURLalloc]initFileURLWithPath:soundPath];

thePlayer = [[AVAudioPlayeralloc]initWithContentsOfURL:musicURLerror:nil];

[thePlayersetDelegate:self];  

[musicURL release];

[thePlayersetVolume:1.0f];

[thePlayerplay];

//2

SystemSoundID soundID;

NSString *path = [[NSBundlemainBundle]pathForResource:@"tishi"ofType:@"caf"];    

CFURLRef soundURL = (CFURLRef)[NSURLfileURLWithPath:path];

AudioServicesCreateSystemSoundID(soundURL,&soundID);

AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);

AudioServicesPlayAlertSound(soundID);


//产品不同的随机数,如果不使用srand((unsigned)time(NULL));每次产品的数都是一样的

    srand((unsigned)time(NULL)); //以时间作为参照标准

    for (int i = 1 ; i <= 10; i++) {

        NSLog(@"%d",rand() %100 +1);

    }


//////////////////////////////////////////////////////////////////////////////////////////////
2进制

    //    for (int i = 0; i < data.length; i++) {

    //

    //        printf("(%x,%d)",receiveByte[i],receiveByte[i]);

    //

    //        int n = receiveByte[i];

    //

    //        int i=0,a[8];

    //        //辗转相除取模

    //        do {

    //            a[i]=n%2;

    //            n/=2;

    //            i++;

    //        }while(n!=0);

    //

    //        for(i--;i>=0;i--)

    //            printf("%i",a[i]);

    //        

    //        printf("\n");

    //    }

    //    printf("\r\n");



原创粉丝点击