Small differences in frame in swift and OC

Source: Internet
Author: User

//the structure of CGRect, Cgpoint and Cgsize in 1.0 OC is as follows:        structCGRect {Cgpoint origin;        Cgsize size;        }; structCgpoint {cgfloat x;        CGFloat y;        }; structcgsize {cgfloat width;        CGFloat height; In the OC environment, when we want to change the frame of a control (for example, x or y, width, height), we have to define a temporary frame (assuming cgrect temp) to get the frame of the current control and then assign a value by modifying the value of temp. Overwrite the previous frame/*such as: UIView *view = [[UIView alloc]init];            View.frame = CGRectMake (100,200,20,60);            We have to do this when we need to change only the x value cgrect tempframe = view.frame;            tempframe.origin.x = 200;        View.frame = Tempframe; */This causes us to make the animation, is more cumbersome. //2.0 See the structure of CGRect in Swift             Public structCGRect { Publicvar origin:cgpoint Publicvar size:cgsize PublicInit () PublicInit (Origin:cgpoint, size:cgsize)} Public structCgpoint { Publicvar x:cgfloat Publicvar y:cgfloat PublicInit () PublicInit (x:cgfloat, y:cgfloat)} extension cgpoint { Public Staticvar Zero:cgpoint {Get }                 PublicInit (x:int, Y:int) PublicInit (x:double, y:double)} from the most basic structure, swift and OC are both structures, but the relative swift two more construction methods, so we can not like in OC to assign a value to a frame//View.frame = {{200,100},{100,300}}From the basic syntax of swift, we know that Var is used to modify variables and can be changed, which means that origin can be changed directly,//Modify the X value to become so simple view.frame.origin.x = 1000 You can modify the original x value directly so that the frame based animation becomes easier

Small differences in frame in swift and OC

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.