//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