記錄一下iOS開發中瑣碎的點點_2

1. modal出來新控制器半透明

modalPresentationStyle屬性必須在presentViewController:以前賦值, 不然無效....html

HandOutMoneyVc *handMoney = [[HandOutMoneyVc alloc] init];
    
    //關鍵語句,必須有
    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
        nextVC.modalPresentationStyle=UIModalPresentationOverCurrentContext; //iOS8以上
    }else{
        self.modalPresentationStyle = UIModalPresentationCurrentContext; // iOS7平臺
    }
    
    [self.navigationController presentViewController:handMoney animated:YES completion:nil];

2. 應用狀態發生變化時候發出的通知

// These notifications are sent out after the equivalent delegate message is called
//應用已經進入後臺   
UIKIT_EXTERN NSString *const UIApplicationDidEnterBackgroundNotification    NS_AVAILABLE_IOS(4_0);
//應用將要進入前臺
UIKIT_EXTERN NSString *const UIApplicationWillEnterForegroundNotification      NS_AVAILABLE_IOS(4_0);
//應用運行成功
UIKIT_EXTERN NSString *const UIApplicationDidFinishLaunchingNotification;
UIKIT_EXTERN NSString *const UIApplicationDidBecomeActiveNotification;
UIKIT_EXTERN NSString *const UIApplicationWillResignActiveNotification;
//收到內存警告
UIKIT_EXTERN NSString *const UIApplicationDidReceiveMemoryWarningNotification;

3. UIViewController的automaticallyAdjustsScrollViewInsets屬性

automaticallyAdjustsScrollViewInsets根據按所在界面的status bar,navigationbar,與tabbar的高度,自動調整scrollview的 inset,設置爲no,不讓viewController調整,咱們本身修改佈局便可。ide

4. NSDecimalNumber的使用

NSValue能夠用來存儲任意數據類型, 包括數字,結構體等數據類型; NSNumber是NSValue的子類, 是專門用來處理數字的一個類; NSDecimalNumber是NSNumber的子類, 提供了一些基本的算術運算功能.佈局

NSDecimal提供的一些類方法:ui

+ (NSDecimalNumber *)zero;
+ (NSDecimalNumber *)one;
+ (NSDecimalNumber *)minimumDecimalNumber;
+ (NSDecimalNumber *)maximumDecimalNumber;
+ (NSDecimalNumber *)notANumber;

- (NSDecimalNumber *)decimalNumberByAdding:(NSDecimalNumber *)decimalNumber;
- (NSDecimalNumber *)decimalNumberByAdding:(NSDecimalNumber *)decimalNumber withBehavior:(nullable id <NSDecimalNumberBehaviors>)behavior;

- (NSDecimalNumber *)decimalNumberBySubtracting:(NSDecimalNumber *)decimalNumber;
- (NSDecimalNumber *)decimalNumberBySubtracting:(NSDecimalNumber *)decimalNumber withBehavior:(nullable id <NSDecimalNumberBehaviors>)behavior;

- (NSDecimalNumber *)decimalNumberByMultiplyingBy:(NSDecimalNumber *)decimalNumber;
- (NSDecimalNumber *)decimalNumberByMultiplyingBy:(NSDecimalNumber *)decimalNumber withBehavior:(nullable id <NSDecimalNumberBehaviors>)behavior;

- (NSDecimalNumber *)decimalNumberByDividingBy:(NSDecimalNumber *)decimalNumber;
- (NSDecimalNumber *)decimalNumberByDividingBy:(NSDecimalNumber *)decimalNumber withBehavior:(nullable id <NSDecimalNumberBehaviors>)behavior;

- (NSDecimalNumber *)decimalNumberByRaisingToPower:(NSUInteger)power;
- (NSDecimalNumber *)decimalNumberByRaisingToPower:(NSUInteger)power withBehavior:(nullable id <NSDecimalNumberBehaviors>)behavior;

- (NSDecimalNumber *)decimalNumberByMultiplyingByPowerOf10:(short)power;
- (NSDecimalNumber *)decimalNumberByMultiplyingByPowerOf10:(short)power withBehavior:(nullable id <NSDecimalNumberBehaviors>)behavior;

5. 判斷控制器是modal出來仍是push出來的,根據不一樣方式進行不一樣的關閉處理

if (self.presentingViewController) {
        [self dismissViewControllerAnimated:YES completion:nil];
    } else {
        [self.navigationController popViewControllerAnimated:YES];
    }

6. 關於UIView的autoresizingMask屬性

typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
    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。

其它的組合相似。atom

摘自:http://www.cnblogs.com/jiangyazhou/archive/2012/06/26/2563041.htmlcode

7. UIScrollView的alwaysBounceVertical屬性

簡單的說, 就是是否會回彈的效果, 相關屬性以下所示, 必須bounces爲YES時候, 下面的兩個屬性纔有效.htm

@property(nonatomic)     BOOL     bounces;                        // default YES. if YES, bounces past edge of content and back again 
@property(nonatomic)     BOOL     alwaysBounceVertical;           // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically 
@property(nonatomic)     BOOL     alwaysBounceHorizontal;         // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag horizontally

8. 指定getter方法的名字

以下所示, getter=isAutomaticallyChangeAlpha, 這樣的聲明, 若是進行了這樣的聲明, 那麼調用get方法須要調用 isAutomaticallyChangeAlpha便可. 這麼作是爲了增長程序的可讀性. 從新指定屬性的getter或者setter方法blog

@property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha;

9. - willMoveToSuperview:的使用

使用:ip

- (void)willMoveToSuperview:(UIView *)newSuperview {

    [super willMoveToSuperview:newSuperview];

    NSLog(@"oldSuperview=%@,newSuperview=%@",self.oldSuperview,newSuperview);

      self.oldSuperview = newSuperview;

    NSLog(@"%s",__func__);

}

10. UIActivityIndicatorView 系統提供的菊花控件

廢話很少說, 如下是蘋果提供的API:內存

//
//  UIActivityIndicatorView.h
//  UIKit
//
//  Copyright (c) 2005-2015 Apple Inc. All rights reserved.
//

#import <UIKit/UIView.h>
#import <UIKit/UIKitDefines.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) {
    UIActivityIndicatorViewStyleWhiteLarge,
    UIActivityIndicatorViewStyleWhite,
    UIActivityIndicatorViewStyleGray __TVOS_PROHIBITED,
};

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIActivityIndicatorView : UIView <NSCoding>

- (instancetype)initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyle)style NS_DESIGNATED_INITIALIZER; // sizes the view according to the style
- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;
- (instancetype) initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
   
@property(nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; // default is UIActivityIndicatorViewStyleWhite
@property(nonatomic) BOOL                         hidesWhenStopped;           // default is YES. calls -setHidden when animating gets set to NO

@property (nullable, readwrite, nonatomic, strong) UIColor *color NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

- (void)startAnimating;
- (void)stopAnimating;
- (BOOL)isAnimating;

@end

NS_ASSUME_NONNULL_END
相關文章
相關標籤/搜索