iOS开发Tips2

来源:互联网 发布:随机森林算法优化研究 编辑:程序博客网 时间:2024/06/05 14:30

  • 随机数的使用
  • 从safari打开链接
  • 禁止锁屏
  • push or present
  • 判断一个特定的点是否落在区域内

---------------------------------------------------------------------

随机数的使用

1)、arc4random() 比较精确不需要生成随即种子

       使用方法 :

        通过arc4random() 获取0到x-1之间的整数的代码如下:

        int value arc4random() x; 


       获取1到x之间的整数的代码如下:

       int value (arc4random() x) 1; 

2)、CCRANDOM_0_1() cocos2d中使用 ,范围是[0,1]

       使用方法:

       float random = CCRANDOM_0_1() * 5; //[0,5]   CCRANDOM_0_1() 取值范围是[0,1]

 3)、random() 需要初始化时设置种子

      使用方法:

      srandom((unsigned int)time(time_t *)NULL); //初始化时,设置下种子就好了。

转自:http://www.cnblogs.com/xuling/archive/2012/02/28/2370692.html


---------------------------------------------------------------------

从safari打开链接

[[UIApplication sharedApplication] openURL:url]; 


---------------------------------------------------------------------

禁止锁屏

[[UIApplication sharedApplication] setIdleTimerDisabled: YES];  


---------------------------------------------------------------------

判断UIViewController是push的还是present进去的
int n = [self.navigationController.childViewControllers count];   if (n>1)   {       //push   }   else   {      //present   } 

---------------------------------------------------------------------

判断一个特定的点是否落在区域内

CGRectContainsPoint(CGRect rect, CGPoint point)

Returns whether a rectangle contains a specified point.

bool CGRectContainsPoint (CGRect rect,CGPoint point);

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event  {      UITouch *touch = [touches anyObject];      CGPoint point = [touch locationInView:self];            if (CGRectContainsPoint(self.thumb.frame, point))      {          //point在rect中的动作      }  } 

0 0
原创粉丝点击