zoukankan      html  css  js  c++  java
  • 新浪微博-整理笔记

    10月26号整理

    1.获得项目中info.plist文件的内容
    1> [NSBundle mainBundle].infoDictionary
    2> 版本号在info.plist中的key:kCFBundleVersionKey
    
    2.自定义控制器的view
    重写loadView方法(不需要调用[super loadView])
    
    3.控制器view的高度和状态栏的关系
    创建控制器的view时,系统会检测状态栏是否显示
    * 如果有状态栏,那么控制器view的高度是460(iPhone5中是548)
    * 如果没有状态栏,那么控制器view的高度是480(iPhone5中是568)
    
    4.[UIScreen mainScreen].applicationFrame的取值
    以3.5inch为例(320x4801> 没有状态栏,applicationFrame的值{{0, 0}, {320, 480}}
    2> 有状态栏,applicationFrame的值{{0, 20}, {320, 460}}
    
    5.按钮的状态
    UIControlStateNormal       普通(默认的状态)
    UIControlStateHighlighted  高亮(用户长按的时候)
    UIControlStateDisabled     失效(通过代码控制:enabled属性)
    UIControlStateSelected     选中(通过代码控制:selected属性)
    
    6.错误调试技巧
    1> 一个控件无法显示出来的可能原因
    * 没有宽高(宽高为0)
    * 位置不对
    * hidden=YES
    * 没有被addSubview到屏幕上
    
    2> 一个UIScrollView无法滚动
    * contentSize没有值
    * 不能接收到触摸事件
    
    3> 一个控件无法跟用户交互(无法接收事件)的可能原因
    * (父控件的)userInteractionEnabled = NO;
    * (父控件的)hidden = YES
    * (父控件的)alpha <= 0.01
    * (父控件的)背景是clearColor
    
    7.按钮的设置
    // 高亮状态下不更改图片的颜色
    self.adjustsImageWhenHighlighted = NO;
    // 是否选中状态
    self.selected = YES;
    // 是否可用状态
    self.enabled = YES;

    10月27号整理

    一、按钮的设置
    0.设置背景图片
    [btn setBackgroundImage:image forState:UIControlStateNormal];
    
    1.设置内部UIImageView的图片
    [btn setImage:image forState:UIControlStateNormal];
    // 不能写成btn.imageView.image = image;
    
    2.设置内部UILabel的文字
    [btn setTitle:@"43" forState:UIControlStateNormal];
    // 不能写成btn.titleLabel.text = @"43";
    
    3.调整内部ImageView的frame
    - (CGRect)imageRectForContentRect:(CGRect)contentRect
    
    4.调整内部UILabel的frame
    - (CGRect)titleRectForContentRect:(CGRect)contentRect
    
    5.覆盖父类在highlighted时的所有操作
    - (void)setHighlighted:(BOOL)highlighted { }
    
    6.文字居中
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    7.文字大小
    self.titleLabel.font = [UIFont systemFontOfSize:12];
    
    8.图片的内容模式
    self.imageView.contentMode = UIViewContentModeCenter;
    
    二、添加子控制器
    - (void)addChildViewController:
    * 会将子控制器添加到childViewControllers,并且子控制器是有顺序的
    * 目的就是持有子控制器,不让子控制器销毁,保证主控制器在,子控制器就在
    
    三、让一个控制器拥有导航栏的最快方法:包装一层导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
    
    四、UIBarButtonItem
    1> 创建一个带有文字的item
    [[UIBarButtonItem alloc] initWithTitle:@"设置" style:UIBarButtonItemStyleBordered target:nil action:nil]
    
    2> 创建一个包装了自定义View的item
    - (id)initWithCustomView:(UIView *)customView
    
    五、设置导航栏UINavigationBar主题
    // 1.appearance方法返回一个导航栏的外观对象
    // 修改了这个外观对象,相当于修改了整个项目中的外观
    UINavigationBar *bar = [UINavigationBar appearance];
    
    // 2.设置导航栏的背景图片
    [bar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    
    // 3.设置导航栏文字的主题
    [bar setTitleTextAttributes:@{
      UITextAttributeTextColor : [UIColor blackColor],
      UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]
     }];
    
    六、设置导航按钮UIBarButtonItem主题
    // 1.修改所有UIBarButtonItem的外观
    UIBarButtonItem *barItem = [UIBarButtonItem appearance];
    // 2.修改item的背景图片
    [barItem setBackgroundImage:image1 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [barItem setBackgroundImage:image2 forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
    // 3.修改item上面的文字样式
    NSDictionary *dict = @{
        UITextAttributeTextColor : [UIColor darkGrayColor],
        UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]
    };
    [barItem setTitleTextAttributes:dict forState:UIControlStateNormal];
    [barItem setTitleTextAttributes:dict forState:UIControlStateHighlighted];
    
    七、设置状态栏样式
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;

    10月29号整理

    一、Cell的设置
    1.设置cell的背景view和选中时的背景view
    UIImageView *bg = [[UIImageView alloc] init];
    bg.image = [UIImage imageNamed:@"abc.png"];
    cell.backgroundView = bg;
    
    UIImageView *selectedBg = [[UIImageView alloc] init];
    selectedBg.image = [UIImage imageNamed:@"cde.png"];
    cell.selectedBackgroundView = selectedBg;
    
    2.设置cell最右边的指示器(比如箭头文本标签)
    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"common_icon_arrow.png"]];
    
    二、tableView的设置
    1.设置table头部和底部的view
    // 底部(宽度固定是320)
    tableView.tableFooterView = footer;
    // 头部(宽度固定是320)
    tableView.tableHeaderView = header;
    
    2.设置每一组头部和底部的高度
    tableView.sectionHeaderHeight = 5;
    tableView.sectionFooterHeight = 0;
    
    3.设置tableView的背景
    // 当tableview的样式为group时,如果想更换背景,必须清除默认条纹状的backgroundView
    // backgroundView的优先级 > backgroundColor
    tableView.backgroundView = nil;
    tableView.backgroundColor = [UIColor redColor];

    10月30号整理

    一、AFN的使用
    1.依赖的框架
    * MobileCoreServices.framework
    * SystemConfiguration.framework
    * Security.framework
    
    2.主头文件:AFNetworking.h
    
    3.创建POST请求对象
    // BaseURL是基准路径,格式为-> 协议头://主机名 ,不能包含其他路径
    AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"https://api.weibo.com"]];
    
    // Method是请求方法
    // path是拼接在基准路径后面的请求路径
    // parameters是POST请求的参数
    NSURLRequest *post = [client requestWithMethod:@"POST" path:@"oauth2/access_token" parameters:@{
                          @"client_id" : kAppKey,
                          @"client_secret" : kAppSecret,
                          @"grant_type" : @"authorization_code",
                          @"redirect_uri" : kRedirectURI,
                          @"code" : requestToken
    }];
    
    4.发送请求,解析服务器的JSON数据
    // 创建操作对象
    NSOperation *op = [AFJSONRequestOperation JSONRequestOperationWithRequest:post
    success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        // AFN认为请求成功会调用
    }
    failure : ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        // AFN认为请求失败会调用
    }];
    
    // 执行操作
    [op start];
    
    5.AFJSONRequestOperation默认不接收text/plain类型的数据,当服务器返回text/plain类型的数据时,会认为出错了。可以通过修改源代码解决问题
    * 修改AFJSONRequestOperation的下列方法
    + (NSSet *)acceptableContentTypes {
        return [NSSet setWithObjects:@"text/plain", @"application/json", @"text/json", @"text/javascript", nil];
    }
    
    二、MBProgressHUD的使用
    1.显示HUD
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"哥正在加载中...";
    hud.dimBackground = YES;
    
    2.移除hud
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    
    三、工具类的作用
    1.封装某一块独立的业务功能,比如存储数据、发送网络请求等
    2.每个工具类的作用
    * HttpTool:负责发送整个微博项目的getpost请求
    * StatusTool:负责管理微博数据:抓取微博数据、发送微博
    * AccountTool:负责管理账号(存储读取账号)

     10月1号

    一、SDWebImage的使用
    1.依赖的框架
    * ImageIO.framework
    * MapKit.framework
    
    2.UIImageView下载图片需要的头文件:UIImageView+WebCache.h
    
    3.调用方法下载图片
    // url是图片路径
    // placeholder是占位图片(正在下载图片时,暂时显示的图片)
    // options是缓存策略
    - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
    - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options
    
    4.缓存策略-SDWebImageOptions
    默认是开启了硬盘内存缓存的
    * SDWebImageRetryFailed   下载失败了会再次尝试下载
    * SDWebImageLowPriority   当UIScrollView等正在滚动时,延迟下载图片(放置scrollView滚动卡)
    * SDWebImageCacheMemoryOnly 只缓存到内存中,不缓存到硬盘上
    * SDWebImageProgressiveDownload 图片会一点一点慢慢显示出来(就像浏览器显示网页上的图片一样)
    * SDWebImageRefreshCached 将硬盘缓存交给系统自带的NSURLCache去处理,当同一个URL对应的图片经常更改时可以用这种策略
    
    一般使用SDWebImageRetryFailed | SDWebImageLowPriority
    
    二、动态改变Cell的高度
    1.利用tableView代理方法的返回值决定每一行cell的高度
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    
    三、UIFont
    // 返回字体的行高
    * [UIFont systemFontOfSize:10].lineHeight

    10月2号

    一、每个Cell高度不一致的一般做法:
    1.自定义一个cell,在initWithStyle:reuseIdentifier:构造方法中添加所有可能显示的子控件
    
    2.新建一个模型类,比如StatusCellFrame,作用是:描述一个Cell内部所有子控件的frame属性
    * 提供一系列CGRect类型的属性给Cell访问
    * 提供一个接口来接收模型数据(比如Status)
    * 在接收模型数据的同时,计算所有子控件的frame和cell的高度
    
    3.回到控制器(代理和数据源)
    1> 在tableView:heightForRowAtIndexPath:方法中利用StatusCellFrame返回cell的高度
    2> 在tableView:cellForRowAtIndexPath:方法中
    * 新建自定义cell
    * 给Cell传递对应的StatusCellFrame对象
    
    4. 自定义Cell
    1> 提供接口接收StatusCellFrame对象
    2> 在接收StatusCellFrame对象的同时,设置所有子控件的frame,设置所有子控件的数据
    
    二、日期处理
    1.将字符串转成NSDate
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *date = [fmt dateFromString:@"2013-08-08 17:45:34"];
    
    2.将NSDate转为字符串
    NSString *timeStr = [fmt stringFromDate:date];

     10月4号

    一、自动伸缩属性
    UIViewAutoresizingNone                 不伸缩
    UIViewAutoresizingFlexibleLeftMargin   跟父控件左边的距离自动伸缩
    UIViewAutoresizingFlexibleRightMargin  跟父控件右边的距离自动伸缩
    UIViewAutoresizingFlexibleTopMargin    跟父控件顶部的距离自动伸缩
    UIViewAutoresizingFlexibleBottomMargin 跟父控件底部的距离自动伸缩
    UIViewAutoresizingFlexibleWidth        宽度跟随父控件宽度自动伸缩
    UIViewAutoresizingFlexibleHeight       高度跟随父控件高度自动伸缩
    
    二、设置按钮(UIButton)文字和图片的间距
    @property(nonatomic) UIEdgeInsets titleEdgeInsets;
    @property(nonatomic) UIEdgeInsets imageEdgeInsets;
    
    三、新浪数据分页传递的参数
    * since_id : 会加载 微博ID > since_id 的数据(也就是时间比较晚、比较新的数据)
    * max_id : 会加载 微博ID <= max_id 的数据(也就是时间比较早、比较旧的数据)
    
    四、MJRefresh的使用
    0.先加入主头文件
    #import "MJRefresh.h"
    
    1.添加下拉刷新
    MJRefreshHeaderView *header = [MJRefreshHeaderView header];
    header.scrollView = self.tableView;
    header.delegate = self;
    
    2.添加上拉加载更多
    MJRefreshFooterView *footer = [MJRefreshFooterView footer];
    footer.scrollView = self.tableView;
    footer.delegate = self;
    
    3.监听刷新状态,有2种方式
    1> 设置代理delegate,一旦控件进入了刷新状态,就会调用delegate的下列方法
    - (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView
    {
        if ([refreshView isKindOfClass:[MJRefreshFooterView class]]) {
            // 上拉加载更多
            
        } else {
            // 下拉刷新
            
        }
    }
    
    2> 设置block回调
    header.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
        
    };
    footer.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
        
    };
    
    4.通过代码进入刷新状态
    [header beginRefreshing]; // 进入刷新状态就会触发相应的代理方法或者block
    [footer beginRefreshing]; // 进入刷新状态就会触发相应的代理方法或者block
    
    5.结束刷新状态,回到普通状态
    [header endRefreshing];
    [footer endRefreshing];
    
    6.可以在MJRefreshBaseView.h中通过控制NeedAudio宏来开启音频功能
    
    7.在MJRefreshFooterView.m和MJRefreshHeaderView.m中可以修改控件显示的文字
    
    五、如果想在内部限制某个控件的宽高,不让外界随便改,可以重写setFrame:方法,在此方法内部设置自己的宽高

    10月5号

    一、导航控制器的代理
    1.UINavigationController的delegate属性
    
    2.代理方法
    1> 即将显示新控制器时调用
    /*
     navigationController : 导航控制器
     viewController : 即将显示的新控制器
     */
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    
    2> 新控制器显示完毕时调用
    /*
     navigationController : 导航控制器
     viewController : 显示完毕的新控制器
     */
    - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    
    二、隐藏控制器刚出现时的滚动条
    重写控制器的viewDidAppear方法,覆盖父类默认的操作:显示滚动条
    
    三、tableView每组的头部控件
    1.控件宽度默认就是tableView的宽度
    2.控件高度由下面的代理方法决定
    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    
    四、通过tableView的代理方法控制某一行的cell能否达到高亮选中状态
    - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
  • 相关阅读:
    合并n个链表
    合并2个链表
    删除链表中的倒数第n个元素
    判断字符串是否回文字符串
    回文链表
    反转链表
    反转链表2
    冒泡排序法
    编译datax(3.x版本)踩的坑,记录修改记录
    Python基本知识(6)——集合
  • 原文地址:https://www.cnblogs.com/needly/p/3401161.html
Copyright © 2011-2022 走看看