国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

IOS開發基礎知識--碎片27

2019-11-14 18:03:06
字體:
來源:轉載
供稿:網友

1:iOS中的round/ceil/floorf

extern float ceilf(float);extern double ceil(double);extern long double ceill(long double);extern float floorf(float);extern double floor(double);extern long double floorl(longdouble);extern float roundf(float);extern double round(double);extern long double roundl(longdouble);round:如果參數是小數,則求本身的四舍五入。ceil:如果參數是小數,則求最小的整數但不小于本身.floor:如果參數是小數,則求最大的整數但不大于本身. Example:如何值是3.4的話,則3.4 -- round 3.000000    -- ceil 4.000000    -- floor 3.00000

 

2:對數組進行轉換,把原來二個值轉化成一條的記錄(滿足左右排版布局)

NSMutableArray *mnewArray=[[NSMutableArray alloc]init];    NSArray *nameArray=@[@"1",@"2",@"3",@"4",@"5",@"6"];    int allCount=0;    if (nameArray.count%2==1) {        //說明是奇數        allCount=nameArray.count;    }    else    {        allCount=nameArray.count-1;    }    for (int i=0; i<allCount; i++) {        userModel *userM=[[userModel alloc]init];        userM.leftName=nameArray[i];        i++;        if (i!=nameArray.count) {            userM.rightName=nameArray[i];        }        [mnewArray addObject:userM];    }

 

3:APP撥打電話完又跳回到APP里,并監聽它的狀態

#import "ViewController.h"#import <CoreTelephony/CTCall.h>#import <CoreTelephony/CTCallCenter.h>@interface ViewController ()<UIAlertViewDelegate>@PRoperty(strong,nonatomic)UIWebView *phoneCallWebView;//電話監聽@property (nonatomic, strong) CTCallCenter * center;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    }- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];}- (IBAction)sdfsdfsdfs:(id)sender {    [self directCall];        //監聽電話    __weak typeof(self) weakSelf = self;    self.center = [[CTCallCenter alloc] init];    self.center.callEventHandler = ^(CTCall* call) {        if ([call.callState isEqualToString:CTCallStateDisconnected])        {            NSLog(@"Call has been disconnected");        }        else if ([call.callState isEqualToString:CTCallStateConnected])        {            NSLog(@"Call has just been connected");        }        else if([call.callState isEqualToString:CTCallStateIncoming])        {            NSLog(@"Call is incoming");        }        else if ([call.callState isEqualToString:CTCallStateDialing])        {            //監聽再進入APP時彈出窗            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AlertViewTest"                                                            message:@"message"                                                           delegate:weakSelf                                                  cancelButtonTitle:@"Cancel"                                                  otherButtonTitles:@"OtherBtn",nil];            [alert show];            NSLog(@"call is dialing");        }        else        {            NSLog(@"Nothing is done");        }    };}//打電話 結束完自動跳回APP-(void)directCall{    NSString *PhoneNum=@"10086";    NSURL *phoneURL=[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",PhoneNum]];    if (!self.phoneCallWebView) {        self.phoneCallWebView=[[UIWebView alloc]initWithFrame:CGRectZero];    }    [self.phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];}@end

注意:監聽電話要引入CoreTelephony.framework,跳轉回APP則是通過一個UIWebView實現

 

4:UIView的layoutSubviews和drawRect方法何時調用

首先兩個方法都是異步執行。layoutSubviews方便數據計算,drawRect方便視圖重繪。

layoutSubviews在以下情況下會被調用:

1、init初始化不會觸發layoutSubviews。

2、addSubview會觸發layoutSubviews。
3、設置view的Frame會觸發layoutSubviews,當然前提是frame的值設置前后發生了變化。
4、滾動一個UIScrollView會觸發layoutSubviews。
5、旋轉Screen會觸發父UIView上的layoutSubviews事件。
6、改變一個UIView大小的時候也會觸發父UIView上的layoutSubviews事件。
7、直接調用setLayoutSubviews。
 
drawRect在以下情況下會被調用:

1、如果在UIView初始化時沒有設置rect大小,將直接導致drawRect不被自動調用。drawRect 掉用是在Controller->loadView, Controller->viewDidLoad 兩方法之后掉用的.所以不用擔心在 控制器中,這些View的drawRect就開始畫了.這樣可以在控制器中設置一些值給View(如果這些View draw的時候需要用到某些變量 值).

2、該方法在調用sizeToFit后被調用,所以可以先調用sizeToFit計算出size。然后系統自動調用drawRect:方法。
3、通過設置contentMode屬性值為UIViewContentModeRedraw。那么將在每次設置或更改frame的時候自動調用drawRect:。
4、直接調用setNeedsDisplay,或者setNeedsDisplayInRect:觸發drawRect:,但是有個前提條件是rect不能為0。
以上1,2推薦;而3,4不提倡
 
drawRect方法使用注意點:

 

1、 若使用UIView繪圖,只能在drawRect:方法中獲取相應的contextRef并繪圖。如果在其他方法中獲取將獲取到一個invalidate 的ref并且不能用于畫圖。drawRect:方法不能手動顯示調用,必須通過調用setNeedsDisplay 或 者 setNeedsDisplayInRect,讓系統自動調該方法。
2、若使用calayer繪圖,只能在drawInContext: 中(類似魚drawRect)繪制,或者在delegate中的相應方法繪制。同樣也是調用setNeedDisplay等間接調用以上方法
3、若要實時畫圖,不能使用gestureRecognizer,只能使用touchbegan等方法來掉用setNeedsDisplay實時刷新屏幕
 
5:UIView中的坐標轉換(convertPoint,convertRect)
// 將像素point由point所在視圖轉換到目標視圖view中,返回在目標視圖view中的像素值- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;// 將像素point從view中轉換到當前視圖中,返回在當前視圖中的像素值- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;// 將rect由rect所在視圖轉換到目標視圖view中,返回在目標視圖view中的rect- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;// 將rect從view中轉換到當前視圖中,返回在當前視圖中的rect- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;例把UITableViewCell中的subview(btn)的frame轉換到 controllerA中// controllerA 中有一個UITableView, UITableView里有多行UITableVieCell,cell上放有一個button// 在controllerA中實現:CGRect rc = [cell convertRect:cell.btn.frame toView:self.view];或CGRect rc = [self.view convertRect:cell.btn.frame fromView:cell];// 此rc為btn在controllerA中的rect或當已知btn時:CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];或CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview];

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 自治县| 大方县| 大宁县| 五寨县| 剑阁县| 淮阳县| 杨浦区| 寿宁县| 乳山市| 平利县| 承德县| 鹿泉市| 阿拉尔市| 筠连县| 濮阳县| 淳化县| 磐石市| 辽中县| 崇义县| 高雄市| 洛川县| 三亚市| 清水河县| 婺源县| 湘潭县| 永和县| 宿迁市| 方城县| 佛坪县| 清苑县| 富裕县| 长乐市| 班玛县| 宝坻区| 光山县| 柞水县| 右玉县| 郴州市| 西乡县| 西充县| 琼中|