iOS-related UI latest Knowledge points summary (i)

Source: Internet
Author: User

This is I learn the UI, feel where the difficulty, easy wrong point, and some not easy to remember points, to share with you, but also hope that you can correct me

    1. [Self.num1 Resignfirstresponder] registered as the first responder
    2. int sum = S1.INTVALUE+[S2 Intvalue] Converts an object into an int type
    3. [Self.view Endediting:yes] Current view resignation of first responder
    4. Uitextfield sometimes does not eject the keyboard commond+k
    5. NSLog (@ "%@", Nsstringfromcgrect (range));
    6. Frame cannot change the value directly: change in the following way
    7. CGRect frame=self. Button.frame;
    8. frame.origin.x-=10;

9.self. Button.frame=frame;

10. When changing frame, sometimes setting use Auto layout may cause the button to not work

11. When setting different control, interface, controller can be distinguished by tag value

12. First-type animation

[UIView Beginanimations:nil Context:nil];

[UIView Setanimationduration:2];

[UIView Setanimationrepeatcount:2];

Set the content of animation changes

[UIView commitanimations];

Use of 13.block animations

[UIView animatewithduration:1 animations:^{

Write code that requires passive painting here

}];, whether block or hand-end animation, is the UIView class method

14.frame and bounds can represent the size of a control. If you modify a frame, the control keeps the upper-left corner intact, and if you modify bounds, the control keeps the center point intact.

15. Move one line of code shortcut keys: cmd + OPTION + [

16. Change the size position of the picture, use transform, bring your own animation effect

Self.pic.transform = cgaffinetransformtranslate (self.pic.transform, 0,-10);//Change offset

Self.pic.transform = Cgaffinetransformrotate (self.pic.transform,m_pi_4);//Change angle

Self.pic.transform = Cgaffinetransformscale (Self.pic.transform, 1.2, 1.2);//change size

. if (self.myimgView.isAnimating) {

Return

}//determines if the animation is being played back directly without performing a button's Click event

_myimgview.animationimages = arr;, sets the animated array of the Uiimageview

_myimgview.animationduration = 0.05*count;//Animation playback time

_myimgview.animationrepeatcount = 2;//Animation Repeat Count

[_myimgview startanimating];//Start animation

Remember to empty the animation array at the end of the animation

[Self Performselector: @selector (Clear) Withobject:nil Afterdelay: (0.05*2*count)];

-(void) clear{

Self.myimgView.animationImages = nil;//Empty After the animation is executed

}

UIImage *image = [UIImage imagenamed:str]; waste memory compared to UIImage *img = [UIImage Imagewithcontentsoffile:path];

[NSBundle Mainbundle] Gets the picture's storage path on the phone based on the name of the picture

self.preBtn.enabled = (Self.index! = 0); Direct judging results as enabling conditions

20. Key to nine Gongge

Line number is

int row = I/colnum;

Column number

int col = I%colnum;

CGFloat LeftMargin = (self.view.frame.size.width-colnum*width-(colNum-1) *xmargin)/2;

CGFloat x = lefemargin + col * (Xmargin + width);

CGFloat y = topMargin + row * (Ymargin + heigth);

21. Use the Tranform to reset

-(ibaction) Rest {

Self.iconImage.transform = cgaffinetransformidentity;

}

22. For push and pop, it means calling Uinavigationcontroller's push-, pop-, or set-method to modify the view controller's stack

23. For switching tabs, it means modifying the SelectedIndex or Selectedviewcontroller properties of the Uitabbarcontroller

24. For modal, it means calling [Uiviewcontroller presentViewController:animated:completion:] or [Uiviewcontroller Dismissviewcontrolleranimated:completion:].

UI control Initialization issues: initWithFrame and Initwithcoder, aweakfromnib execution

1>. (1) Pure code-created UI controls do not perform aweakfromnib methods and Initwithcoder methods.

(2) The Layoutsubciews method is called after the control has been initialized (the end of itself and the instantiation of the child control) to get to the current control's frame so that it can be laid out for the child control. If there are child controls, it is called two times.

2.> (1) Creating UI controls through Xib does not call the Init and Initwith methods.

(2) Initwithcoder and aweakfromnib in the same role here, are called by the system, when loading from Xib/storybord file UIView, Initwithcoder will execute.

25. If you are directly based on frame, you should ensure that only the view is added at initialization time, instead of setting their frame, the process of setting up the sub-view frame is all in the Layoutsubviews method: Do not rely on the previous calculation results, It should always be calculated based on the current latest value.

26. Constraint issues:

If you are laying out based on the Auto layout constraints, you can add constraints to the Commoninit call, and do not override the Layoutsubviews method, because its default implementation is to calculate the frame based on constraints. Most importantly, set the Translatesautoresizingmaskintoconstraints property to NO to avoid nsautoresizingmasklayoutconstraint constraints if you use Masonry Frame, then do not worry about this problem, the Mas_makeconstraints method will first set this property to No:, do not understand it

[Self.view SizeToFit] We generally call the SizeToFit method when the manual layout is not convenient, the following we will look specifically at which situations, not suitable for manual layout:

1.navigationBar Settings for Navigationitem (add two views above the control to item)

2. Settings for Uibarbuttonitem in toolbar (generally we also add a spring control)

Above two kinds of occasions can use SizeToFit this method, let the system give us to do automatic layout. (Note: If you add a control, we can set the Fram directly)

3. In Tabbar We cannot manually add the child controls, because Tabbar is automatically added according to the controller system by default Tabbaritem. (Guess the system may also automatically call this method)

Add text to 4.UILabel, then adjust the label size to fit the text, we also call the SizeToFit method

28. Set the color by taking a color meter

float red = (float) 125/255;

float green = (float) 125/255;

float blue = (float) 125/255;

Uicolor *col = [Uicolor colorwithred:red green:green blue:blue alpha:1];

[Uitextfield object Setkeyboardtype:uikeyboardtypenumberpad]; set keyboard

[Uitextfield object Setborderstyle:uitextborderstylenone]; Set Border type

}completion:^ (BOOL finished) {is the code that is called when the Block animation is completed

[Uitextfield Object setplaceholder:@ "Please enter ..."];

[Uitextfield object Setsecuretextentry:yes]; The text of the Password text box must be a dark text display (mask display) secure property

[Uitextfield object Setborderstyle:uitextborderstyleroundedrect]; The border is round

[Self.view Endediting:yes]; Remember to exit the keyboard after editing, enhance the user experience

34. When using UIView remember, if there is a button click event, remember to open user interaction userinteractionenabled

[Self.answerView.subviews makeobjectsperformselector: @selector (Removefromsuperview)]; Clear all child controls inside the view

36. Button click of the large image effect (that can zoom can also be reduced)

-(Ibaction) CLICKMAINBTN: (UIButton *) Sender {

if (Self.cover==nil) {

[Self showbig];

}else{

[Self showsmall];

}

}

-(void) showbig{

UIButton *cover = [[UIButton alloc]init];

Cover.frame = Self.view.frame;

Cover.backgroundcolor = [Uicolor blackcolor];

Cover.alpha = 0;

[Self.view Addsubview:cover];

CGFloat width = self.view.frame.size.width;

CGFloat height = width;

CGFloat x = 0;

CGFloat y = (self.view.frame.size.height-width)/2;

[Cover addtarget:self action: @selector (Showsmall) forcontrolevents:uicontroleventtouchupinside];

[UIView Animatewithduration:2 animations:^{

Cover.alpha = 0.5;

Self.mainIconBtn.frame = CGRectMake (x, y, width, height);

[Self.view BringSubviewToFront:self.mainIconBtn];

}];

}

-(void) showsmall{

[UIView Animatewithduration:2 animations:^{

Self.mainIconBtn.frame = self.orign;

Self.cover.alpha = 0;

} completion:^ (BOOL finished) {

[Self.cover Removefromsuperview];

}];

}

37. Add a timer.

-(void) addtimer{

Self.mytimer = [Nstimer scheduledtimerwithtimeinterval:2 target:self selector: @selector (playpic) Userinfo:nil repeats : YES];

Why??

[[Nsrunloop Mainrunloop]addtimer:self.mytimer formode:nsrunloopcommonmodes]; Message loop mode must be changed

}

-(void) removetimer{

[Self.mytimer invalidate];

}

38. Set two font colors for Pagecontroller

Page.pageindicatortintcolor = [Uicolor Bluecolor];

Page.currentpageindicatortintcolor = [Uicolor Redcolor];

39. Add two unique forms of the parent control

[Self.view insertsubview:page BelowSubview:self.sView];

[Self.view insertsubview:page AboveSubview:self.sView];

40. Set the offset of the ScrollView

[Self.sview setcontentoffset:cgpointmake (num*self.sview.frame.size.width, 0) Animated:yes];

41. Several key factors in setting up Pagecontroller

1) Self.myPage.currentPage (generally implemented in ScrollView proxy method Scrollviewdidscroll)

2) Page.numberofpages

3) Set the timer inside the ScrollView

-(void) scrollviewwillbegindecelerating: (Uiscrollview *) scrollview{

[Self addtimer];

}//[self.sview Setcontentoffset:cgpointmake Animated:yes]; When you start the offset by setting the offset, call and

-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate{

[Self removetimer];

}//Stop dragging (manual drag)

ScrollView default is not scrolling, you need to set a parameter to scroll contentsize

43. Set the maximum and minimum magnification for the scrollview.

Self.scrollView.maximumZoomScale = 3; Self.scrollView.minimumZoomScale = 0.4;

44. Zoom in and out of pictures with ScrollView settings

Self.sview.delegate = self;

Self.sview.minimumZoomScale = 0.3;

Self.sview.maximumZoomScale = 2;

-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) scrollview{

return scrollview.subviews[0];

}

45. When scrolling through this offset, the last one does not add animation effect

if (self.pagecontrol.currentpage!=4) {

[Self.sview Setcontentoffset:po Animated:yes];

}else{

[Self.sview Setcontentoffset:po];

}

46. Set the way to change the Pageconteoller page number when the picture is half rolling:

CGFloat s = self.sview.contentoffset.x;

CGFloat x = self.sview.frame.size.width;

int num1 = (s+0.5*x)/x;

Self.pageControl.currentPage = NUM1;

47. Setting the status bar

}

-(BOOL) prefersstatusbarhidden{

return YES;

}

48. Set two column cmd+option+ Enter, cancel two columns option+ enter

49. Change the settings on one side option+ to the right, select the left

50. Directly created tab remember to set the data source self.tableView.dataSource = self;

iOS-related UI latest Knowledge points summary (i)

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.