self. View.frame.size.height = 100f; this cannot be compiled, and the compiler will error "expression is not assignable" because there are two different meanings of the points in this sentence. Self.view.frame is the objective-c syntax, is the frame property that reads the View property, using a point in objective-c to access the property is just a syntactic sugar, so self.view.frame this sentence will be converted to: [[Self View] frame In other words, this is actually a message delivery. The Frame property is a cgrect structure, so frame.size.height is the C language syntax, which is to access the Size field in the CGRect structure, and the height is a field of the cgsize structure. So, your sentence actually equals: [[self view] frame].size.height = 100f, and objective-c is just an extension of the C language, so the above sentence will be transferred to the C language function call form, similar to this form: GetFrame(). size. height = +f; in C, the return value of a function is a r-value, and it cannot be assigned directly (the so-called R-value, which can only appear to the right of the equal sign, you can understand as a constant While the l-value can be assigned, it can appear on the left side of the equal sign, usually a variable. Therefore, when you intend to assign a value directly to the return value of a function, the compiler tells you that "this expression cannot be assigned". This is the reason why the error occurred. So, the solution is to save the return value of the function with a temporary variable, modify the temporary variable, and then assign it to frame://1. Saves the return value with a temporary variable. CGRect temp = self.view.frame; 2. Assign a value to the variable. Since the variables are l-value, they can be assigned temp.size.height = 100f; 3. Modify the value of frame self.view.frame = temp; |
Self.view.frame.size.height = 100f; this cannot be compiled, the compiler will error "expression is not assignable"