日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS开发基础知识--碎片27

發布時間:2025/3/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS开发基础知识--碎片27 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

?iOS開發基礎知識--碎片27

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:weakSelfcancelButtonTitle:@"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];

?

總結

以上是生活随笔為你收集整理的iOS开发基础知识--碎片27的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。