Basic knowledge of IOS development-fragment 27 and basic knowledge of ios-27

Source: Internet
Author: User

Basic knowledge of IOS development-fragment 27 and basic knowledge of ios-27

1: round/ceil/flodorf in iOS

Extern float ceilf (float); extern double ceil (double); extern long double ceill (long double); extern float flograding (float); extern double floor (double ); extern long double floorl (longdouble); extern float roundf (float); extern double round (double); extern long double roundl (longdouble); round: If the parameter is a decimal, the result is rounded to the nearest integer. Ceil: If the parameter is a decimal number, the smallest integer is obtained but not smaller than itself. floor: If the parameter is a decimal number, calculate the largest integer but not greater than itself. example: If the value is 3.4, then 3.4 -- round 3.000000 -- ceil 4.000000 -- floor 3.00000

 

2: Convert the array to convert the original two values into a record (satisfying the layout of the left and right layout)

NSMutableArray * mnewArray = [[NSMutableArray alloc] init]; NSArray * nameArray = @ [@ "1", @ "2", @ "3", @ "4 ", @ "5", @ "6"]; int allCount = 0; if (nameArray. count % 2 = 1) {// The description is odd 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: After the APP calls the phone, it jumps back to the APP and listens to its status.

# Import "ViewController. h "# import <CoreTelephony/CTCall. h> # import <CoreTelephony/CTCallCenter. h> @ interface ViewController () <UIAlertViewDelegate> @ property (strong, nonatomic) UIWebView * phoneCallWebView; // call listener @ property (nonatomic, strong) CTCallCenter * center; @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad];}-(void) didreceivemorywarning {[super didreceivemorywarning] ;}-(IBAction) sdfsdfsdfs :( id) sender {[self directCall]; // listen to the phone number _ weak typeof (self) weakSelf = self; self. center = [[CTCallCenter alloc] init]; self. center. callEventHandler = ^ (CTCall * call) {if ([call. callState islog tostring: 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]) {// when the listener enters the APP, the window 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") ;};}// automatically jump back to the APP after the call ends-(void) directCall {NSString * PhoneNum = @ "10086 "; NSURL * phoneURL = [NSURL URLWithString: [NSString stringWithFormat: @ "tel: % @", PhoneNum]; if (! Self. Warn) {self. phoneCallWebView = [[UIWebView alloc] initWithFrame: CGRectZero];} [self. phoneCallWebView loadRequest: [NSURLRequest requestWithURL: phoneURL];} @ end

Note: CoreTelephony. framework should be introduced to the listening phone. The redirection back to the APP is implemented through a UIWebView.

 

4: when to call the layoutSubviews and drawRect methods of UIView

First, both methods are executed asynchronously. LayoutSubviews facilitate data computing and drawRect facilitate view re-painting.

LayoutSubviews will be called in the following cases:

1. Initialization of init will not trigger layoutSubviews.

2. addSubview triggers layoutSubviews.
3. Setting the view Frame triggers layoutSubviews. Of course, the premise is that the frame value has changed before and after setting.
4. Rolling a UIScrollView triggers layoutSubviews.
5. Rotating Screen triggers the layoutSubviews event on the parent UIView.
6. Changing the size of a UIView triggers the layoutSubviews event on the parent UIView. 7. Call setLayoutSubviews directly. DrawRect is called in the following cases:

1. If the rect size is not set during UIView initialization, The drawRect will not be automatically called. DrawRect is used after the Controller-> loadView, Controller-> viewDidLoad method. so don't worry about the drawRect of these views in the controller. in this way, you can set some values for the View in the Controller (if some variable values are required for the View draw ).

2. This method is called after sizeToFit is called. Therefore, you can call sizeToFit to calculate the size. Then the system automatically calls drawRect: method.
3. Set the value of contentMode to UIViewContentModeRedraw. The drawRect: is automatically called every time the frame is set or changed :.
4. Call setNeedsDisplay directly or setNeedsDisplayInRect to trigger drawRect:, but there is a precondition that the rect cannot be 0.
1, 2 and 3 are not recommended.
Note the following when using the drawRect method:

 

1. If you use UIView for plotting, you can only obtain the corresponding contextRef in the drawRect: method and plot it. If it is obtained in other methods, an invalidate ref will be obtained and cannot be used for drawing. DrawRect: The call method cannot be displayed manually. You must call setNeedsDisplay or setNeedsDisplayInRect to enable the system to automatically call this method.
2. If calayer is used for plotting, it can only be drawn in drawInContext: (similar to drawRect) or in the corresponding method of delegate. The preceding method is also called indirectly, such as setNeedDisplay.
3. To draw images in real time, you cannot use gestureRecognizer. You can only use methods such as touchbegan to use setNeedsDisplay to refresh the screen in real time. 5: convertPoint, convertRect)
// Convert the pixel point from the view where the point is located to the target view, and return the pixel value-(CGPoint) convertPoint :( CGPoint) point toView (UIView *) view in the target view; // switch the pixel point from the view to the current view, and return the pixel value-(CGPoint) convertPoint :( CGPoint) point fromView (UIView *) view in the current view; // convert the rect view from the rect view to the target view, and return the rect-(CGRect) convertRect :( CGRect) rect toView :( UIView *) view in the target view; // switch the rect from the view to the current view, and return the rect-(CGRect) convertRect :( CGRect) rect fromView :( UIView *) view in the current view; for example, convert the frame of subview (btn) in UITableViewCell to controllerA. // There Is A UITableView in controllerA. There are multiple UITableVieCell lines in UITableView, and a button in the cell is implemented in controllerA: CGRect rc = [cell convertRect: cell. btn. frame toView: self. view]; or CGRect rc = [self. view convertRect: cell. btn. frame fromView: cell]; // This rc is a rect of btn in controllerA or CGRect rc = [btn when btn is known. superview convertRect: btn. frame toView: self. view]; or CGRect rc = [self. view convertRect: btn. frame fromView: btn. superview];

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.