• iOS开发基础知识--碎片12


     

     iOS开发基础知识--碎片12

    1:Delegate运用

    复制代码
    .h
    #import <UIKit/UIKit.h>
    @protocol FilterHeaderViewDelegate <NSObject>
    @required
    -(void)filterHeaderViewMoreBtnClicked:(id)sender;
    @end
    
    extern float CYLFilterHeaderViewHeigt;
    @interface FilterHeaderView : UICollectionReusableView
    @property (nonatomic, weak  ) id<FilterHeaderViewDelegate> delegate;
    @end
    
    .m
    - (void)moreBtnClicked:(id)sender {
        if ([self.delegate respondsToSelector:@selector(filterHeaderViewMoreBtnClicked:)]) {
            [self.delegate filterHeaderViewMoreBtnClicked:self.moreButton];
        }
    }
    注意在.m中会有要调用上面这个方法:
    [self.moreButton addTarget:self action:@selector(moreBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    而在调用这个插件的时候记得把delegate赋于self,并要把FilterHeaderViewDelegate引入到<>里;然后就可以实现这个deletage的方法;
    复制代码

    2:实现UIButton不同状态下的显示

    复制代码
    [btn setTitle:@"更多" forState:UIControlStateNormal];
        [btn setTitle:@"收起" forState:UIControlStateSelected];
        btn.titleLabel.font = [UIFont systemFontOfSize:12];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
        btn.adjustsImageWhenHighlighted = NO;
        [btn setImage:[UIImage imageNamed:@"home_btn_more_normal"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"home_btn_more_selected"] forState:UIControlStateSelected];
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, -btn.imageView.frame.size.width-kImageToTextMargin, 0, btn.imageView.frame.size.width);
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, btn.titleLabel.frame.size.width, 0, -btn.titleLabel.frame.size.width);
    复制代码

    3:视图uiview增加点击事件

    复制代码
        if (!_TicketView) {
            _TicketView=[UIView new];
            _TicketView.backgroundColor=[UIColor whiteColor];
            //增加点击事件
            UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TickAction:)];
            [_TicketView addGestureRecognizer:tapGesture];
            [_BelowView addSubview:_TicketView];
        }
    
    调用:
    
    -(void)TickAction:(id)sender
    {
        NSLog(@"sdfsdfsdf");
    }
    复制代码

    4:在ios7中出现滚动视图UIScrollView不兼容问题,无法滚动

    把contentSize定义放在viewDidLayoutSubviews中;
    -(void)viewDidLayoutSubviews
    {
        _myScrollView.contentSize=CGSizeMake(SCREEN_WIDTH,600);
    }

    5:对UIButton上的图标进行翻转

    #define DEGREES_TO_RADIANS(angle) ((angle)/180.0 *M_PI)
    
    调用:
    _BtnMoreContent.imageView.transform = CGAffineTransformRotate(_BtnMoreContent.imageView.transform, DEGREES_TO_RADIANS(180));

    6:创建一个背景图片,并从网络动态加载

    复制代码
    在viewDidLoad调用:
    
    -(void)LoadBackViewImage
    {
        UIImageView *bgView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        
        bgView.image=[UIImage imageNamed:@"bgWeatherEmpty"];
        
        [bgView sd_setImageWithURL:[NSURL URLWithString:self.backImageUrl] placeholderImage:[UIImage imageNamed:@"bgWeatherEmpty"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            dispatch_async(dispatch_get_main_queue(), ^{
                bgView.image=image;
                [self.view addSubview:bgView];
                [self.view sendSubviewToBack:bgView];
            });
        }];
    }
    
    注意:
    
    UIView层次管理(sendSubviewToBack,bringSubviewToFront)
     将一个UIView显示在最前面只需要调用其父视图的 bringSubviewToFront()方法。
    将一个UIView层推送到背后只需要调用其父视图的 sendSubviewToBack()方法。
    复制代码

    7:加载xib到其它视图中

    复制代码
    创建一个UIView的xib文件,这个方程可以看网上随便一个文章,主要是把属性中的custom Class指定给创建的那个 .h文件;
    
    .h
    #import <UIKit/UIKit.h>
    
    @interface LKTextView : UIView
    @property (strong, nonatomic) IBOutlet UILabel *lbText;
    - (IBAction)bt_pressed:(id)sender;
    @property (strong, nonatomic) IBOutlet UITextField *textView;
    +(LKTextView*)instanceTextView;
    @end
    
    .m
    #import "LKTextView.h"
    #import "RKTabView.h"
    #import "RKTabItem.h"
    @implementation LKTextView
    @synthesize textView;
    @synthesize lbText;
    
    +(LKTextView *)instanceTextView
    {
        NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"LKTextView" owner:nil options:nil];
        return [nibView objectAtIndex:0];
    }
    -(id)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
        if(self)
        {
            //其它自个想增加到视图里的
            [self initViews];
            
        }
        return self;
    }
    /**
     *  @author wujunyang, 15-04-30 16:04:03
     *
     *  @brief  这边是运用RKTABVIEW创建一个标签的
     */
    -(void)initViews
    {
        UIView *vi=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 30)];
        vi.backgroundColor=[UIColor redColor];
        [self addSubview:vi];
        
        RKTabView *titledTabsView=[[RKTabView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
        [self addSubview:titledTabsView];
        
        RKTabItem *mastercardTabItem = [RKTabItem createUsualItemWithImageEnabled:nil imageDisabled:[UIImage imageNamed:@"mastercard"]];
        mastercardTabItem.titleString = @"MasterCard";
        RKTabItem *paypalTabItem = [RKTabItem createUsualItemWithImageEnabled:nil imageDisabled:[UIImage imageNamed:@"paypal"]];
        paypalTabItem.titleString = @"PayPal";
        RKTabItem *visaTabItem = [RKTabItem createUsualItemWithImageEnabled:nil imageDisabled:[UIImage imageNamed:@"visa"]];
        visaTabItem.titleString = @"Visa";
        RKTabItem *wuTabItem = [RKTabItem createUsualItemWithImageEnabled:nil imageDisabled:[UIImage imageNamed:@"wu"]];
        wuTabItem.titleString = @"Western Union";
        RKTabItem *wireTabItem = [RKTabItem createUsualItemWithImageEnabled:nil imageDisabled:[UIImage imageNamed:@"wire-transfer"]];
        wireTabItem.titleString = @"Wire Transfer";
        
        //mastercardTabItem.tabState = TabStateEnabled;
        
        titledTabsView.darkensBackgroundForEnabledTabs = YES;
        titledTabsView.horizontalInsets = HorizontalEdgeInsetsMake(25, 25);
        titledTabsView.titlesFontColor = [UIColor colorWithWhite:0.9f alpha:0.8f];
        
        titledTabsView.tabItems = @[mastercardTabItem, paypalTabItem, visaTabItem, wuTabItem, wireTabItem];
    }
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect
    {
        // Drawing code
    }
    */
    
    - (IBAction)bt_pressed:(id)sender {
        lbText.text = textView.text;
    }
    @end
    
    然后调用视图.m:
    
    - (void)viewDidLoad
    {
        
       LKTextView* text = [LKTextView instanceTextView];
        text.frame = CGRectMake(100, 100, text.frame.size.width, text.frame.size.height);
        text.textView.text = @"input ";
       [self.view addSubview:text];
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    复制代码

     8:不错的插件

    复制代码
    AutoLayout下自动计算UITableViewCell高度的扩展FDTemplateLayoutCell    https://github.com/forkingdog/UITableView-FDTemplateLayoutCell
    多视图控制器间进行切换--XLPagerTabStrip                              https://github.com/xmartlabs/XLPagerTabStrip
    不错的标签选项卡插件                                                 https://github.com/RafaelKayumov/RKTabView
    生成@3x图片对应的@2x和@1x版本--RTImageAssets                         https://github.com/rickytan/RTImageAssets
    使用:用来生成 @3x 的图片资源对应的 @2x 和 @1x 版本,只要拖拽高清图到 @3x 的位置上,然后按 Ctrl+Shift+A 即可自动生成两张低清的补全空位。当然你也可以从 @2x 的图生成 @3x 版本,如果你对图片质量要求不高的话
    复制代码

    9:ios7和ios8关于导航栏的那些事

    复制代码
    ios7之前的版本中UIViewController中的view在显示后会自动调整为去掉导航栏的高度的,控件会自动在导航栏以下摆放。
    
    在iOS7中UIViewController的wantsFullScreenLayout属性被舍弃了,所有的UIViewController创建后默认就是full Screen的,因此如果带导航栏的应用界面中的部分控件会被导航栏覆盖掉。
    
    解决方案:可以使用ios7种UIViewController新增的属性extendLayoutIncludesOpaqueBars和edgesForExtendedLayout来解决。
    
    其中这个属性指定了当bar使用不透明图片时,试图是否延伸至bar所在区域,默认值为NO。而edgesForExtendedLayout
    
    其中这个属性指定了当Bar使用了不透明图片时,视图是否延伸至Bar所在区域,默认值时NO。而edgesForExtendedLayout则是表示视图是否覆盖到四周的区域,默认是UIRectEdgeAll,即上下左右四个方向都会覆盖,那么为让顶部不进行延伸到导航栏覆盖的区域,我们可以把顶部区域延伸去掉。实现代码如下:
    
    
    self.extendedLayoutIncludesOpaqueBars = NO;
    
    self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;
    复制代码

     11:initWithNibName/awakeFromNib/initWithCoder区别

    复制代码
    第一、initWithNibName这个方法是在controller的类在IB中创建,但是通过Xcode实例化controller的时候用的. 
    第二、initWithCoder 是一个类在IB中创建但在xocde中被实例化时被调用的.比如,通过IB创建一个controller的nib文件,然后在xcode中通过 initWithNibName来实例化这个controller,那么这个controller的initWithCoder会被调用.或者是一个view的nib文件,类似方法创建时调用initWithCoder 
    第三、awakeFromNib 
     
    当.nib文件被加载的时候,会发送一个awakeFromNib的消息到.nib文件中的每个对象,每个对象都可以定义自己的awakeFromNib函数来响应这个消息,执行一些必要的操作。也就是说通过nib文件创建view对象时执行awakeFromNib 
    
    第四、关于 initWithNibName 和 loadNibNamed 的区别和联系 : 
     
    
     关于 initWithNibName 和 loadNibNamed 的区别和联系。之所以要把这两者来一起讲,我觉的我也有点困惑,到底用那种?其实真正搞清楚了他们之间的差别,就不会这么迷惘了。因为这两个方法,根本就不是一路货色。 
     既然,是要说明这2个方法,那就着重将区别吧。 
     但是第一步,还是要罗嗦一下,他们的联系:可以使用此方法加载用户界面(xib文件)到我们的代码中,这样,可以通过操作这个加载进来的(xib)对象,来操作xib文件内容。 
     下面进入主题,谈区别: 
    1. ShowViewController的initWithNibName方法 
    ShowViewController * showMessage = [[ShowViewController alloc] 
     initWithNibName:@"ShowViewController" bundle:nil]; 
     self.showViewController = showMessage; 
     [showMessage release]; 
     2.VideoCellController的loadNibNamed方法 
    NSArray * nib = [[NSBundle mainBundle] loadNibNamed:@"Save3ViewController" 
     owner:self options:nil] ; 
     self.showViewController = [nib lastObject]; 
     [nib objectAtIndex:0]; 
     
    
    
    总结: 
     只看他们初始化,那可能感觉是一样的。但是如果,打开分别看xib的关系的时候,才恍然大悟,原来他们的集成类都不一样。 
    1. initWithNibName要加载的xib的类为我们定义的视图控制器类 
    2.加载方式不同 
    initWithNibName方法:是延迟加载,这个View上的控件是 nil 的,只有到 需要显示时,才会不是 nil 
     loadNibNamed方法:即时加载,用该方法加载的xib对象中的各个元素都已经存在。 
     (认真理解这句帮规:when using loadNibNamed:owner:options:, the File's Owner should be NSObject, the main view should be your class type, and all outlets should be hooked up to the view, not the File's Owner.) 
     
    
     第五、initWithCoder和initWithFrame的区别 
     
    
    nitWithoder 是当从nib文件中加载对象的时候会调用,比如你的view来自nib那么就会调用这个view的这个函数。(由框架调用) 
    initWithFrame (是由用户调用,来初始化对象的) 
  • 相关阅读:
    Oracle体系结构详细图解
    了解Oracle体系结构(超详细)
    Oracle 12C DataGuard部署以及维护
    RAC上,对于buffer cache的全局锁,称为PCM锁,当然,对于enq,lc的锁,称为non-PCM锁
    oracle锁与死锁概念,阻塞产生的原因以及解决方案
    Oracle 多粒度锁机制介绍
    Master Note For Oracle Database Upgrades and Migrations (Doc ID 1152016.1)
    Oracle 12c和18c中的MGMTDB(下)
    AIX系统性能管理之Oracle案例分析
    Web安全从入门到“放弃”之暴力破解
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/5792219.html
Copyright © 2020-2023  润新知