UI之窗口与视图-创新互联-成都快上网建站

UI之窗口与视图-创新互联

----------UI窗口于视图的创建示例----------

在北票等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、网站制作 网站设计制作按需求定制网站,公司网站建设,企业网站建设,成都品牌网站建设,全网营销推广,成都外贸网站建设公司,北票网站建设费用合理。

在window上创建赤橙黄绿青蓝紫七个视图,互相嵌套,设置定时器,每秒每个视图随机变换颜色,并且旋转,十秒后停止,视图全部移除。

---AppDelegate.h中声明视图和一个计时的变量

@interface AppDelegate : UIResponder

{

  UIView *view1;

  UIView *view2;

  UIView *view3;

  UIView *view4;

  UIView *view5;

  UIView *view6;

  UIView *view7;

  int second;

}

---AppDelegate.m中实现题中要求

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  CGRect rect = [UIScreen mainScreen].bounds;

  //创建主Window

  self.window = [[UIWindow alloc]initWithFrame:rect];

  self.window.backgroundColor = [UIColor blackColor];

  [self.window makeKeyAndVisible];

 

  //创建View

  view1 = [[UIView alloc]initWithFrame:CGRectMake(70, 70, 250, 250)];

  view1.backgroundColor= [UIColor redColor];

  view1.tag = 1;

 

  view2 = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 220, 220)];

  view2.backgroundColor= [UIColor orangeColor];

  view3 = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 190, 190)];

  view3.backgroundColor= [UIColor yellowColor];

  view4 = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 160, 160)];

  view4.backgroundColor= [UIColor greenColor];

  view5 = [[UIView alloc]initWithFrame:CGRectMake(15, 15 , 130, 130)];

  view5.backgroundColor= [UIColor cyanColor];

  view6 = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 100, 100)];

  view6.backgroundColor= [UIColor blueColor];

  view7 = [[UIView alloc]initWithFrame:CGRectMake(25, 25, 50, 50)];

  view7.backgroundColor= [UIColor purpleColor];

  [self.window addSubview:view1];

  [view1 addSubview:view2];

  [view2 addSubview:view3];

  [view3 addSubview:view4];

  [view4 addSubview:view5];

  [view5 addSubview:view6];

  [view6 addSubview:view7];

 

  second = 10;

  //定时器

  [NSTimer scheduledTimerWithTimeInterval:1

                                    target:self

                                  selector:@selector(timeAction:)

                                  userInfo:nil

                                  repeats:YES];

 

 

 

      return YES;

}

- (void)timeAction:(NSTimer *)timer{

  //七个视图颜色随机变

  view1.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];

  view2.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];

  view3.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];

  view4.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];

  view5.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];

  view6.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];

  view7.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1];

 

  //旋转

  UIView *view = [self.window viewWithTag:1];

  CGAffineTransform trans = view.transform;

  view.transform = CGAffineTransformRotate(trans, M_PI/10);

 

 

  //十秒后计时器停止,视图移除

  second--;

  if (second < 0) {

      [timer invalidate];

      [view1 removeFromSuperview];

      return;

  }

     

}

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


新闻名称:UI之窗口与视图-创新互联
本文网址:http://kswjz.com/article/dhdhch.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流