iOS開發經驗總結(3)

一、調節UINavigationBar的leftBarButtonItem離左邊的距離

UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back-button-whiteArrow.png"] style:UIBarButtonItemStylePlain target:self action:@selector(logoutBarBtnPressed:)];

UIBarButtonItem *fixedBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

fixedBarButtonItem.width = -15;

self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:fixedBarButtonItem, buttonItem, nil];

二、RestKit 保存數據到core data
通過RestKit將數據保存到core data中,entity為

@interface Article : NSManagedObject

@property (nonatomic, retain) NSNumber* articleID;
@property (nonatomic, retain) NSString* title;
@property (nonatomic, retain) NSString* body;
@property (nonatomic, retain) NSDate* publicationDate;

@end

@implementation Article // We use @dynamic for the properties in Core Data
@dynamic articleID;
@dynamic title;
@dynamic body;
@dynamic publicationDate;

@end

設置object mapping

RKEntityMapping* articleMapping = [RKEntityMapping mappingForEntityForName:@"Article"
                                                      inManagedObjectStore:managedObjectStore];
[articleMapping addAttributeMappingsFromDictionary:@{
                                                     @"id": @"articleID",
                                                     @"title": @"title",
                                                     @"body": @"body",
                                                     @"publication_date": @"publicationDate"
                                                     }];

articleMapping.identificationAttributes = @[ @"articleID" ];

其中的identificationAttributes 設置的數組中的值,就是用來判斷返回的數據是更新還是new。
三、RestKit 添加relationship
Author Entity

@interface Author : NSObject

@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *email;

@end

Article Entity

@interface Article : NSObject

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *body;
@property (nonatomic) Author *author;
@property (nonatomic) NSDate *publicationDate;

@end

添加好關系friendship

// Create our new Author mapping
RKObjectMapping* authorMapping = [RKObjectMapping mappingForClass:[Author class] ];

// NOTE: When your source and destination key paths are symmetrical, you can use addAttributesFromArray: as a shortcut instead of addAttributesFromDictionary:

[authorMapping addAttributeMappingsFromArray:@[ @"name", @"email" ]];

// Now configure the Article mapping
RKObjectMapping* articleMapping = [RKObjectMapping mappingForClass:[Article class] ];
[articleMapping addAttributeMappingsFromDictionary:@{
                                                     @"title": @"title",
                                                     @"body": @"body",
                                                     @"publication_date": @"publicationDate"
                                                     }];

// Define the relationship mapping
[articleMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"author"
                                                                               toKeyPath:@"author"
                                                                             withMapping:authorMapping]];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:articleMapping
                                                                                        method:RKRequestMethodAny
                                                                                   pathPattern:nil keyPath:@"articles"
                                                                                   statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

在Json轉Model的時候,使用JTObjectMapping方法很類似。減少很多的工作量。
四、xcode找不到設備
原因:Deployment Target版本比真機版本高,導致找不到。將Deployment Target設置成與真機的系統版本一致。
五、autolayout 自動布局
autoLayout 需要在- (void)viewDidLoad
方法執行完后生效,所以需要在- (void)viewDidAppear:(BOOL)animated
方法中再進行frame的獲取,此時才能取到正確的frame。
六、Navigation backBarButtonItem 設置
根據蘋果官方指出:backbarbuttonItem不能定義customview,所以,只能貼圖或者,讓leftBarButtonItem變成自定義返回按鈕,自己寫個方法進行[self.navigationController pop當前Item
之前大家是否疑惑為什么設置了類似這樣的代碼

UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                               initWithTitle:@"返回"
                               style:UIBarButtonItemStylePlain
                               target:self
                               action:nil];

self.navigationItem.backBarButtonItem = backButton;

界面上backButton并沒出現“返回”的字樣.
其實是被leftBarButtonItem和rightBarButtonItem的設置方法所迷惑了leftBarButtonItem和rightBarButtonItem設置的是本級頁面上的BarButtonItem,而backBarButtonItem設置的是下一級頁面上的BarButtonItem.比如:兩個ViewController,主A和子B,我們想在A上顯示“刷新”的右BarButton,B上的BackButton顯示為“撤退”就應該在A的viewDidLoad類似方法中寫:

UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc]
                                  initWithTitle:@"刷新"
                                  style:UIBarButtonItemStylePlain
                                  target:self
                                  action:nil];

self.navigationItem.rightBarButtonItem = refreshButton;

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
                                 initWithTitle:@"撤退"
                                 style:UIBarButtonItemStylePlain
                                 target:self
                                 action:nil];

self.navigationItem.backBarButtonItem = cancelButton;

而B不需要做任何處理然后ApushB就可以了.
七、AFNetworking 使用ssl

sharedClient.securityPolicy.allowInvalidCertificates = YES;

八、NSJSONSerialization 使用數據類型要求
進行JSON轉化的時候,需要滿足一下的要求。
An object that may be converted to JSON must have the following properties:
The top level object is an NSArray or NSDictionary.
All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
All dictionary keys are instances of NSString.
Numbers are not NaN or infinity.

也就是說:nil,基礎數據不能轉化為JSON。
九、NSArray進行不定參數處理

+ (NSArray *)arrayWithObjectsExceptionNil:(id)firstObj, ...
{
    NSMutableArray *tempMArray = [[NSMutableArray alloc] initWithCapacity:5];
    id eachObject = nil;
    va_list argumentList;

    if ( firstObj ) {
        [tempMArray addObject:firstObj];
        va_start(argumentList, firstObj);

        while ( (eachObject = va_arg(argumentList, id))){
            if ( nil != eachObject ){
                [tempMArray addObject:eachObject];
            }
        }

        va_end(argumentList);
    }

    return nil;
}

十、獲取version

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

    // app名稱
    NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    // app版本
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    // app build版本
    NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];

注意:appid,在申請提交的時候,在itunesconnect的這個里面生成了,審核通過了也不會改變。
十一、no input file 錯誤
如果在編譯的時候找不到文件,需要先在Build Phases中的Compile Sources 將不存在的文件刪除,然后再將找不到的文件添加到project中。
十二、cg,cf,ca,ui等開頭類
你還可以看到其他名字打頭的一些類,比如CF、CA、CG、UI等等,比如CFStringTokenizer 這是個分詞的東東CALayer 這表示Core Animation的層CGPoint 這表示一個點UIImage 這表示iPhone里面的圖片
CF說的是Core Foundation,CA說的是Core Animation,CG說的是Core Graphics,UI說的是iPhone的User Interface
十三、file's owner 含義
file's owner 就是xib對應的類,如view對應的xib文件的file's owner對應的類就是viewcontroller的類。file’s owner 是view和viewcontroller之間的對應關系的橋梁。(即,一個視圖,如何知道自己的界面的操作應該由誰來響應)
十四、iOS coin 不透明
一般iOS app coin應該是不透明的,并且不可以在app中多次使用app coin。
十五、判斷自定義類是否重復
自定義類庫中,需要重寫NSObject的兩個固定方法來判斷類是否重復:

- (BOOL)isEqual:(id)anObject;
- (NSUInteger)hash;

十六、IOS常用宏

// Macro wrapper for NSLog only if debug mode has been enabled
#ifdef DEBUG
#define DLog(fmt,...) NSLog(fmt, ##__VA_ARGS__);
#else
// If debug mode hasn't been enabled, don't do anything when the macro is called
#define DLog(...)
#endif

#define MR_ENABLE_ACTIVE_RECORD_LOGGING 0

#define IS_OS_6_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
#define IS_OS_7_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
#define OBJISNULL(o) (o == nil || [o isKindOfClass:[NSNull class]] || ([o isKindOfClass:[NSString class]] && [o length] == 0))
#define APP ((AppDelegate*)[[UIApplication sharedApplication] delegate])
#define UserDefaults                        [NSUserDefaults standardUserDefaults]
#define SharedApplication                   [UIApplication sharedApplication]
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
#define RGB(r, g, b)                        [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
#define RGBA(r, g, b, a)                    [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

十七、判斷是否是4寸屏

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

十八、NSString格式限定符

說明符 描述
%@ Objective-c 對象
%zd NSInteger
%lx CFIndex
%tu NSUInteger
%i int
%u unsigned int
%hi short
%hu unsigned short
%% %符號

十九、聲明變量 在ARC下自動初始化為nil
NSString *s;

非ARC的情況下, s指向任意地址,可能是系統地址,導致崩潰。
ARC的情況下,s已經自動初始化為nil。
二十、向NSArray,NSDictionary等容器添加元素需判nil
[_paths addObject:[_path copy]];

如果這個_path為nil,那么就會出現一個crash。因為在容器中不能存放nil,可以用[NSNull null]來保存.
推薦 pod 'XTSafeCollection', '~> 1.0.4'
第三方庫,對數組的越界,賦值nil,都有保護作用。

二十一、ceil命令 floor命令
Math中一個算法命令。函數名: ceil用 法: double ceil(double x);功 能: 返回大于或者等于指定表達式的最小整數頭文件:math.h
float f = 1.2222;
NSLog(@"f is %f.", ceil(f));

打印: f is 2.000000.
函數名: floor功 能: 返回小于或者等于指定表達式的最大整數用 法: double floor(double x);頭文件:math.h
float f = 1.2222;NSLog(@"f is %f.", floor(f));

打印: f is 1.000000.

二十二、Xcode中對某個類進行非ARC的設置
在Xcode點擊工程,在工程中選擇“TARGETS”你的工程,在Build Phases中選擇“Compile Sources”,找到你需要設置非ARC的類,在這個類的右邊有一個“Compiler Flags”,在這個里面設置“-fno-objc-arc”。那么這個類就是非ARC進行編譯了。

二十三、storyboard上不能進行scrollview滾動
storyboard上不能進行scrollview滾動的原因是: autolayout引起的

二十四、延長APP的啟動時

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [NSThread sleepForTimeInterval:3.0f];

    return YES;

}

二十五、xcode調試的時候不運行watchdog
在利用Xcode進行調試時,watchdog不會運行,所在設備中測試程序啟動性能時,不要將設備連接到Xcode。

二十六、語言國際化 NSLocalizedString
如果你使用的是Localizable.strings,那么你在程序中可以這樣獲取字符串:NSLocalizedString(@"mykey", nil)

如果你使用的是自定義名字的.strings,比如MyApp.strings,那么你在程序中可以這樣獲取字符串:
NSLocalizedStringFromTable (@"mykey",@"MyApp", nil)

這樣即可獲取到"myvalue"這個字符串,可以是任何語言。

二十七、UIAppearance 使用
使用UIAppearance進行外觀的自定義。
[+ appearance]
修改整個程序中某個class的外觀
[[UINavigationBar appearance] setTintColor:myColor];

[+ appearanceWhenContainedIn:]
當某個class被包含在另外一個class內時,才修改外觀。
[[UILabel appearanceWhenContainedIn:[cusSearchBar class], nil] setTextColor:[UIColor redColor]];

二十八、將NSString轉換成UTF8編碼的NSString
在使用網絡地址時,一般要先將url進行encode成UTF8格式的編碼,否則在使用時可能報告網址不存在的錯誤,這時就需要進行轉換下面就是轉換函數:

NSString *urlString= [NSString stringWithFormat:@"http://www.baidu.com"];
NSString *encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, (CFStringRef)urlString, NULL, NULL,  kCFStringEncodingUTF8 ));
NSURL *url = [NSURL URLWithString:encodedString];

或者使用下面的方法:

NSString *utf8Str = @"Testing";NSString *unicodeStr = [NSString stringWithCString:[utf8Str UTF8String] encoding:NSUnicodeStringEncoding];

有時候獲取的url中的中文等字符是亂碼,網頁內容是亂碼,需要進行一下轉碼才能正確識別NSString,可以用下面的方法:
//解決亂碼問題()

NSString *transString = [NSString stringWithString:[string stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

二十九、NSDateFormatter設定日期格式 AM

NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setAMSymbol:@"AM"];
[dateFormatter setPMSymbol:@"PM"];
[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mmaaa"];
NSDate *date = [NSDate date];

NSString *s = [dateFormatter stringFromDate:date];

顯示效果為:10/05/2010 03:49PM
三十、判斷NSString為純數字

//判斷是否為整形:

- (BOOL)isPureInt:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}

//判斷是否為浮點形:

- (BOOL)isPureFloat:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    float val;
    return[scan scanFloat:&val] && [scan isAtEnd];
}

if( ![self isPureInt:insertValue.text] || ![self isPureFloat:insertValue.text])
{
    resultLabel.textColor = [UIColor redColor];

    resultLabel.text = @"警告:含非法字符,請輸入純數字!";

    return;
}

三十一、image的正確使用
iOS中從程序bundle中加載UIImage一般有兩種方法。第一種比較常見:imageNamed
第二種方法很少使用:imageWithContentsOfFile

為什么有兩種方法完成同樣的事情呢?imageNamed的優點在于可以緩存已經加載的圖片。蘋果的文檔中有如下說法:This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.
這種方法會在系統緩存中根據指定的名字尋找圖片,如果找到了就返回。如果沒有在緩存中找到圖片,該方法會從指定的文件中加載圖片數據,并將其緩存起來,然后再把結果返回。
而imageWithContentsOfFile
方法只是簡單的加載圖片,并不會將圖片緩存起來。這兩個方法的使用方法如下:
UIImage *img = [UIImage imageNamed:@"myImage"]; // caching // or UIImage *img = [UIImage imageWithContentsOfFile:@"myImage"]; // no caching

那么該如何選擇呢?
如果加載一張很大的圖片,并且只使用一次,那么就不需要緩存這個圖片。這種情況imageWithContentsOfFile比較合適——系統不會浪費內存來緩存圖片。
然而,如果在程序中經常需要重用的圖片,那么最好是選擇imageNamed方法。這種方法可以節省出每次都從磁盤加載圖片的時間。
三十二、將圖片中間部分放大
根據圖片上下左右4邊的像素進行自動擴充。

UIImage *image = [UIImage imageNamed:@"png-0016"];
UIImage *newImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(50, 50, 50, 50) resizingMode:UIImageResizingModeStretch];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 200, 400)];
imageView.image = newImage;
imageView.contentMode = UIViewContentModeScaleAspectFill;

使用方法- (UIImage )resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0); // the interior is resized according to the resizingMode
進行對圖片的拉伸,可以使用UIImageResizingModeTile和UIImageResizingModeStretch兩種拉伸方式。
*注意: **此方法返回一個新的UIImage,需要使用這個新的image。
注:UIEdgeInsets設置的值不要上下或左右交叉,不然會出現中間為空白的情況。
在Xcode5中也可以使用新特性 Slicing,直接對圖片進行設置,不需要在代碼中設置了。

三十三、UIImage和NSData的轉換

NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
UIImage *aimage = [UIImage imageWithData:imageData];
//UIImage 轉化為 NSData
NSData *imageData = UIImagePNGRepresentation(aimage);

三十四、NSDictionary和NSData轉換

// NSDictionary -> NSData:
NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:myDictionary];

// NSData -> NSDictionary:
NSDictionary *myDictionary = (NSDictionary*) [NSKeyedUnarchiver unarchiveObjectWithData:myData];

三十五、NSNumberFormatter 價格采用貨幣模式
如果顯示的數值為價格,則用貨幣模式

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
self.introView.guaranteedDataLabel.text = [formatter stringFromNumber:self.quoteEntity.guranteedInfo.guaranteedPrice];

三十六、畫虛線的方法

CGFloat lengths[] = {5, 5};

CGContextRef content = UIGraphicsGetCurrentContext();

CGContextBeginPath(content);

CGContextSetLineWidth(content, LINE_WIDTH);

CGContextSetStrokeColorWithColor(content, [UIColor blackColor].CGColor);

CGContextSetLineDash(content, 0, lengths, 2);

CGContextMoveToPoint(content, 0, rect.size.height - LINE_WIDTH);

CGContextAddLineToPoint(content, rect.size.width, rect.size.height - LINE_WIDTH);

CGContextStrokePath(content);

CGContextClosePath(content);

三十七、設備轉屏

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeLeft;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}

在storyboard中設置只支持豎屏,可以在單個UIViewController中加入這3個方法,使得這個UIViewController只支持左橫屏。
三十八、UITextField 彈出UIDatePicker
設置UITextField的inputView可以不彈出鍵盤,而彈出UIDatePicker。
首先需要在View加載結束的時候指定文本的InputView

UIDatePicker *datePicker = [[UIDatePicker alloc] init];  
datePicker.datePickerMode = UIDatePickerModeDate;  
[datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];  
self.txtDate.inputView = datePicker;

然后需要指定當UIDatePicker變動的時候的事件是什么. 此處就是為了給文本框賦值.

- (IBAction)dateChanged:(id)sender  
{  
    UIDatePicker *picker = (UIDatePicker *)sender;  
    self.txtDate.text = [NSString stringWithFormat:@"%@", picker.date];

}

然后當文本框編輯結束時, 需要讓UIDatePicker消失.

- (IBAction)doneEditing:(id)sender  
{  
    [self.txtDate resignFirstResponder];  
}

然后把文本框在IB中, 指向定義好的txtDate就行了~

三十九、將Status Bar字體設置為白色
在Info.plist中設置UIViewControllerBasedStatusBarAppearance
為NO

在需要改變狀態欄顏色的ViewController中在ViewDidLoad方法中增加:
UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

如果需要在全部View中都變色,可以寫在父類的相關方法中。

四十、UILongPressGestureRecognizer執行2次的問題
//會調用2次,開始時和結束時

- (void)hello:(UILongPressGestureRecognizer *)longPress
{
    if (longPress.state == UIGestureRecognizerStateEnded)//需要添加一個判斷
    {
        NSLog(@"long");

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"hello"

                                                        message:@"Long Press"

                                                       delegate:self

                                              cancelButtonTitle:@"OK"

                                              otherButtonTitles:nil, nil];

        [alert show];
    }
}

四十一、View中事件一次響應一個

self.scrollView.exclusiveTouch = YES;

設置exclusiveTouch這個屬性為YES。
四十二、UIScrollView中立即響應操作
delaysContentTouches 屬性是UIScrollView中立即響應Touch事件。默認是YES,如果想點擊后馬上有反應,則將該值設置為NO。

四十三、UITableView在Cell上添加自定義view
如果在UITableView上添加一個自定義的UIView,需要注意在view中的顏色會因為Cell被選中的點擊色,而引起view的顏色變化,并且不可逆。

四十四、NSNotificationCenter 注銷
當 NSNotificationCenter 注冊一個通知后

- (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullableNSString *)aName object:(nullableid)anObject;

在class的dealloc中,一定要使用

- (void)removeObserver:(id)observer name:(nullable NSString *)aName object:(nullable id)anObject;

進行注銷。
不能用 - (void)removeObserver:(id)observer;
進行通知的注銷。
注意: 如果不注銷,將導致class不會被釋放。

四十五、H5開發的弊端
H5開發的弊端: 占用內容太多。在打開H5的時候,會占用大量的內存,在項目中看到,一般會達到一個頁面50M的內存。
四十六、interactivepopgesturerecognizer 使用
設置left bar button后,會導致右滑返回的效果失效,查看完美的設置方案。
同時為了獲取到右滑返回的事件,可以執行
[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(back)];

在ViewController中viewDidAppare中添加,在viewWillDisappear中remove。

四十六、masonry 中使用兩個UIView之間設置layout

[self.bottomOpenStoreBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(promptImageView.mas_bottom).with.offset(30);
        make.height.mas_equalTo(44);
        make.width.mas_equalTo(SCREEN_WIDTH - 30);
        make.centerX.mas_equalTo(self.promptScrollView);
        make.bottom.mas_equalTo(self.promptScrollView.mas_bottom).with.offset(-30);
    }];

設置self.bottomOpenStoreBtn的頂部與promptImageView的頂部距離30ptmake.bottom.mas_equalTo(self.promptScrollView.mas_bottom).with.offset(-30);
其中的 self.promptScrollView.mas_bottom 必須使用mas_bottom,不能使用bottom.
make.top 中的top為- (MASConstraint*)top
而self.promptScrollView.bottom 中的bottom為

- (float) bottom
{    return CGRectGetMaxY (self.frame);
}

即一個是layout屬性,另一個為frame的屬性。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,825評論 6 546
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,814評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,980評論 0 384
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 64,064評論 1 319
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,779評論 6 414
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 56,109評論 1 330
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 44,099評論 3 450
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,287評論 0 291
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,799評論 1 338
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,515評論 3 361
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,750評論 1 375
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,221評論 5 365
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,933評論 3 351
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,327評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,667評論 1 296
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,492評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,703評論 2 380

推薦閱讀更多精彩內容

  • 一、 cocoa pods 常用的framework 二、 NSInteger打印以及字符串的轉換 使用%zd打印...
    蝴蝶之夢天使閱讀 4,751評論 9 66
  • *面試心聲:其實這些題本人都沒怎么背,但是在上海 兩周半 面了大約10家 收到差不多3個offer,總結起來就是把...
    Dove_iOS閱讀 27,199評論 30 471
  • 一、 iPhone Size 手機型號屏幕尺寸 iPhone 4 4s320 * 480 iPhone 5 5s3...
    Luc_閱讀 734評論 0 0
  • 總結這幾年所遇見的坑 一、 iPhone Size 二、 給navigation Bar 設置 title 顏色 ...
    無灃閱讀 528評論 0 0
  • 面試介紹忌無趣,我自己的特點,與報考專業相關,不用搞笑, 不用浪費時間,老師打斷,就不用說了, 回答禮節,回答完畢...
    尋覓110閱讀 188評論 1 0