获取视图的宽度和高度
float viewWidth=self,view,bounds.size.width;
float viewHeight= self.view.bounds.size.height;
从视图中选取一个随机位置
首先在viewDidLoad中初始化一个随机数生成器 srandom(time(0));
float x= randrom()%(int)(viewWidth-2*BALL_RADIUS);
float y= randrom()%(int)(viewHeight-2*BALL_RADIUS);
spot是一个对象,使用随机坐标来设置对象的位置frame
[spot setFrame:CGRectMake(x,y,BALL_RADIUS*2,BALL_RADIUS*2)];