Animation effect imitation from the foreign site Readme.io login interface, super cute owl, the specific effect as shown.
Animation Implementation Core:
The core of the animation is the transform attribute of UIView in iOS, and then the four images are panned and scaled according to their dimensional coordinates.
The specific layer structure:
Note the point:
-
Only two points of the arm is shown, it is not required to cut, some can block the pink view. So you can put them in a view with the head picture.
-
The way in which the arm in the animation only reveals the pink text box above, is to add two arm images to a different view, and then set the view's properties to be automatically cropped for more than UIView parts.
Core code:
Panning relative to the initial position
self. Greenview. Transform = cgaffinetransformmaketranslation( 0);
//panning relative to the last position
self. Greenview. Transform = cgaffinetransformtranslate(self. Greenview. Transform, 0);
2 is a multiplier relative to the initial size
self. Greenview. Transform = Cgaffinetransformmakescale(2, 2);
//scale 0.5 times times relative to the last size
self. Greenview. Transform = Cgaffinetransformscale(self. Greenview. Transform, 0.5, 0.5);
Step 1:
The main view is created in Storyborad
1. Place two small arms pictures and head images in a view.
2. Place the two long arms in a view, then stack the view into the 1 view, the position corresponds, the hand can be blindfolded, the view's properties to be set to go beyond the partial automatic cropping. The color of the view is transparent.
3. The result of the final view is this.
Step 2:
Given the encapsulation of the code, we can associate this entire view with a UIView class.
1. Drag the 4 pictures in the diagram to the newly created class, create 4 Uiimageview properties. Drag lines across a view
Arm is a long arm.
@property (weak, nonatomic) iboutlet uiimageview *leftarm ;
@property (weak, nonatomic) iboutlet uiimageview * Rightarm;
Hand is the two little dots.
@property (weak, nonatomic) iboutlet uiimageview * LeftHand;
@property (weak, nonatomic) iboutlet uiimageview *righthand ;
Full view with 5 images
@property (weak, nonatomic) iboutlet UIView * Viewframe;
2. Initialize the control in the Awakefromnib method
Get the position of the arm picture relative to an entire view, and the width of the entire view
Position of the current left hand
cgfloat leftarmx = self. Leftarm. Frame. Origin. x;
cgfloat leftarmy = self. Leftarm. Frame. Origin. Y;
//Current right-hand position
cgfloat rightarmx = self. Rightarm. Frame. Origin. x;
cgfloat rightarmy = self. Rightarm. Frame. Origin. Y;
//viewframe width and height
cgfloat Viewframeh = self. Viewframe. Frame. Size. Height;
cgfloat Viewframew = self. Viewframe. Frame. Size. width;
Based on the above data, the position of the arm in the initial state (note: The arm is blindfolded when setting the picture, the initial state arm is not visible, only two dots (hand))
//To facilitate future calculations, set the initial position of the left-hand to the property
//15 size to fit the position of the picture
self. Leftarmx =-leftarmx - ;
self. Leftarmy = Viewframeh - leftarmy;
self. Rightarmx = Viewframew - rightarmx - self. Rightarm. Frame. Size. Width +;
self. Rightarmy = Viewframeh - rightarmy;
//Based on the initial position of the calculated left and wrong hand, set the offset of the initial position
self. Rightarm. Transform = cgaffinetransformmaketranslation(self. Rightarmx, self . Rightarmy);
self. Leftarm. Transform = cgaffinetransformmaketranslation(self. Leftarmx, self . Leftarmy);
Add four properties
@property (nonatomic,assign)cgfloat leftarmx;
@property (nonatomic,assign)cgfloat leftarmy;
@property (nonatomic,assign)cgfloat rightarmx;
@property (nonatomic,assign)cgfloat rightarmy;
3. There are two kinds of owl's state, blindfolded and not eye-blind
Convenient to call, style: [Self.loginanim startanim:yes];
- (void)startanim:(BOOL)iscoverd
{
if (iscoverd) {
//Animation duration 0.25 seconds
[UIView animatewithduration:0.25 animations: ^{
//Blindfold
}];
}Else
{
[UIView animatewithduration:0.25 animations: ^{
//No blindfold, that is, initial state
}];
}
}
1. Blindfold Status
//Arm offset to blindfolded position
self . Rightarm . Transform = cgaffinetransformtranslate ( self . Rightarm . Transform , - self . Rightarmx , - self . Rightarmy );
self. Leftarm. Transform = cgaffinetransformtranslate(self. Leftarm. Transform, -self. Leftarmx, -self. Leftarmy);
//small dots move to the position of the eye, 30 is the size manually adjusted according to the picture display position
cgaffinetransform righthand = cgaffinetransformtranslate ( self . Rightarm . Transform , - self . Rightarmx , - self . Rightarmy + );
cgaffinetransform leftHand = cgaffinetransformtranslate(self. Leftarm. Transform, -self. Leftarmx, -self. Leftarmy+);
//small dots gradually decrease in the process of moving
self. Righthand. Transform = Cgaffinetransformscale(righthand, 0.01, 0.01);
self. LeftHand. Transform = Cgaffinetransformscale(leftHand, 0.01, 0.01);
2. No blindfold
//Two arms back to initialization state
self. Rightarm. Transform = cgaffinetransformmaketranslation(self. Rightarmx, self . Rightarmy);
self. Leftarm. Transform = cgaffinetransformmaketranslation(self. Leftarmx, self . Leftarmy);
//Two small dots back to default settings
self. Righthand. Transform = cgaffinetransformidentity;
self. LeftHand. Transform = cgaffinetransformidentity;
The animated Owl login animation is now complete.
Moe Owl Login Interface animation iOS implementation analysis