zoukankan      html  css  js  c++  java
  • iOS学习——iOS开发小知识点集合

      在iOS学习和开发过程中,经常会遇到一些很小的知识点和问题,一两句话就可以解释清楚了,这样的知识点写一篇随笔又没有必要,但是又想mark一下,以备不时之需,所以就有了本文。后面遇到一些小的知识点会不断更新和整理。

    Question 1: 在iOS开发中经常会遇到定义属性时有getter赋值语句,在UIView.h文件中有下面这么一行代码,这里的getter表示什么意思呢,又有什么作用呢?

    //在UIView.h文件中有这么一行代码
    @property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;

    Answer:这里的getter是你手动指定的getter函数,这样你可以写自己的getter函数。上面的代码表示属性userInteractionEnabled的get方法是 - (BOOL) isUserInteractionEnabled ,而并不是 - (BOOL)userInteractionEnabled ,我们在实际的应用中可以通过view.userInteractionEnabled获取该属性值,实际上是调用.m文件中的 - (BOOL) isUserInteractionEnabled 方法来获取的,同样的,我们也可以直接通过view.isUserInteractionEnabled直接调用该方法获取userInteractionEnabled的属性值。

    如果这里不写getter参数,即定义如下,那么其get方法就应该是 - (BOOL)userInteractionEnabled 了。

    @property(nonatomic) BOOL userInteractionEnabl;

    Question 2:OC中是否可以用点语法调用方法?

    Answer:可以,OC中可以用点语法直接调用方法,但是有一个前提条件就是该方法调用不需要传参,这也是在Masonry框架中链式语法的主要原因。

    Question 3在iOS布局中,当父视图和子视图的透明度(alpha)的值不一致时,父子视图的透明度都以父视图设置的值为准

  • 相关阅读:
    Longest Common Prefix
    Roman to Integer
    Intger to Roman
    Container With Most Water
    Regular Expression Matching
    atoi
    Rotate List
    54. Search a 2D Matrix && Climbing Stairs (Easy)
    53. Minimum Window Substring
    52. Sort Colors && Combinations
  • 原文地址:https://www.cnblogs.com/mukekeheart/p/8446604.html
Copyright © 2011-2022 走看看