zoukankan      html  css  js  c++  java
  • UIView

    UIView  UIImageView的相关操作:

    1.初始化

        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(,,,)];

    2.查询某个view所有的子view,返回结果是数组

         NSArray *subViews = [bigView subviews];

    3.通过数组下标,找到某个固定的子view

         UIView *midView = [subViews objectAtIndex:1];

    4.在固定层级插入视图

         [view insertSubview:insertView atIndex:1];

    5.在某一个子视图的上面插入

       [view insertSubview:insertView aboveSubview:midView];

    6.在某一个字视图的下面插入

       [view insertSubview:insertView belowSubview:midView];

    7.从父视图中移除

       [insertView removeFromSuperview];

    8.交换2个视图的层次

       [ view exchangeSubviewAtIndex:0 withSubviewAtIndex:2];

       [view sendSubviewToBack:midView];//将某一个子视图放到最下面

       [view bringSubviewToFront:midView];//将某一个字视图放到最上面

    9.延迟调用

       [self performSelector:@selector(runLater:) withObject:midView afterDelay:3];

    10.允许子视图跟随,当父视图被放大缩小的时候,子视图也会跟随的

        bigView.autoresizesSubviews = YES;

    11.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;

        autoresizingMask它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高。

       //    UIViewAutoresizingNone                 = 0,
       //    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
       //    UIViewAutoresizingFlexibleWidth        = 1 << 1,
       //    UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
       //    UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
       //    UIViewAutoresizingFlexibleHeight       = 1 << 4,
       //    UIViewAutoresizingFlexibleBottomMargin = 1 << 5

      UIViewAutoresizingNone就是不自动调整。
      UIViewAutoresizingFlexibleLeftMargin 自动调整与superView左边的距离,保证与superView右边的距离不变。
      UIViewAutoresizingFlexibleRightMargin 自动调整与superView的右边距离,保证与superView左边的距离不变。
      UIViewAutoresizingFlexibleTopMargin 自动调整与superView顶部的距离,保证与superView底部的距离不变。
      UIViewAutoresizingFlexibleBottomMargin 自动调整与superView底部的距离,也就是说,与superView顶部的距离不变。
      UIViewAutoresizingFlexibleWidth 自动调整自己的宽度,保证与superView左边和右边的距离不变。
      UIViewAutoresizingFlexibleHeight 自动调整自己的高度,保证与superView顶部和底部的距离不变。
      UIViewAutoresizingFlexibleLeftMargin  |UIViewAutoresizingFlexibleRightMargin 自动调整与superView左边的距离,保证与左边的距离和右边 的距离和原来距左边和右边的距离的比例不变。比如原来距离为20,30,调整后的距离应 为68,102,即68/20=102/30。

    12.CGRect rect = [[UIScreen mainScreen] bounds];

       //获取整个屏幕的rect

       //frame是相对于父视图的rect,bounds是相对于自己的rect,一般情况下前两位数字都是0,rect里的4个数字是分成2组的:一组rect.origin代表坐标,rect.size代表大小

    13.view的动画回调

        [UIView animateWithDuration:2 animations:^{

               view.alpha = 0;

          }completion:^(BOOL finished){

             NSLog(@"动画完成以后回调");

             view.alpha = 1;

          }];

    14.[UIView beginAnimations:nil context:NULL];//准备开始一个动画

         [UIView setAnimationDuration:1];//设置时间

         [UIView commitAnimations];//提交动画

          //启动一个动画的简单写法

          [UIView animateWithDuration:1 animations:^{

               view.frame = rect;

          }];

    15.UIImageView的初始化

         UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(,,,)];

         iv.image = [UIImage imageNamed:@"aaa"];

         //设置需要展示的图片
         //从iphone4开始,屏幕都是retina,(高清,视网膜)
         //系统会自动寻找aaa@2x.png,如果找到了,就做为高清图片来处理。
         //如果找不到aaa@2x.png,就寻找aaa.png
         //实际开发中,图片的大小需要和imageView相匹配。

    16.如果图片的大小和imageView的大小不一致,可能需要设置图片的展示模式

         iv.contentMode = UIViewContentModeCenter;

    17.使用一个图片初始化imageView

         UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

  • 相关阅读:
    mysql报错:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.
    MD5登陆密码的生成
    15. 3Sum、16. 3Sum Closest和18. 4Sum
    11. Container With Most Water
    8. String to Integer (atoi)
    6. ZigZag Conversion
    5. Longest Palindromic Substring
    几种非线性激活函数介绍
    AI初探1
    AI初探
  • 原文地址:https://www.cnblogs.com/Angelone/p/4385267.html
Copyright © 2011-2022 走看看