In fact, you seem to be confused about frames and boundaries. In fact, they are light. Always remember that any view has its own coordinate system. The properties of the frame, center, and transformation are expressed in the coordinates of the observation, and the boundaries are expressed in the view's own coordinate system. If the view does not have a supervisor (not yet installed in the view hierarchy), it still has a frame. In iOS, the frame property is computed from the boundaries of the view, center, and transform. You may ask, what is the feature of the frame and the center when there is no supervisor. They are used when you add a view to another view, allowing you to position the view before it is actually displayed.
The most common example where the boundaries of a view are different from its frame is when it is not in the upper left corner of its supervisor: its bounds.origin may be CGPointZero, but its frame.origin may not. Another classic example is UIScrollView, which often modifies its bounds.origin to do scroll scrolling (in fact, changing the origin of the coordinate system automatically moves each subquery without affecting their frames), while its own frame is constant.
Return to your code. First of all, when you already have images to display in images, it makes sense to initiate views with their images:
UIImageView *face1view = [[UIImageView alloc] initWithImage: sadface];
This helps the correct image size. It is not recommended to initialize views with -init , because this may skip some important code in their initializer, -initWithFrame:
Since you are adding face1view to self.view, you really should use its borders, not your frame:
face1view.frame = self.view.bounds;
The same goes for a happy face. Then in -touchesMoved:โฆ you need to either change the face2view frame to move it inside self.view, or (if self.view does not contain any other views except faces), change the frames of self.view to move both sides inside . Instead, you do something strange, like vertically stretching a happy face inside face2view. If you want a happy face to slide from the bottom of self.view, you must first set its frame as this (not visible at first):
face2view.frame = CGRectOffset(face2view.frame, 0, CGRectGetHeight(self.view.bounds));
If you decide to exchange faces by changing the borders of the images (as opposed to changing the boundaries of self.view), I think you might want to change both the original images of the representations, and the sad face will pop out and the happy face will slide up. Alternatively, if you want a happy face to embrace a sad:
face2view.frame = face1view.frame;