记录一下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
相关文章
相关标签/搜索