Now let's get started with our warning box interface, so that it's easy to implement in this demo, it's just a simple picture instead of a plain code interface with a label and a button. Let's start creating this interface.
cgfloat alertdimension = 250 CGRect alertviewframe = CGRectMake (Self.window .bounds .size .width /2 -Alertdimension/2 , Self.window .size .height /2 -Alertdimension/2 , Alertdimension, alertdimension) Span class= "hljs-comment"; UIView *alertview = [[UIView alloc] Initwithframe:alertviewframe]
First, we need to create an UIView object to act as our virtual warning box and set its location to the center of the screen. This is done by dividing the width and height of the full screen by 2 and subtracting the width and height of the warning box. I like to set the frame of an object to its final position after it finishes the animation, and then adjust its size or position by manipulating its Transform property. In this way, when adding an animation, CGRect I can remove the completed action on the transform than the frame that recalculates it. This is also why if I want it to become 1.5 times times more, than animating its entire frame, having to calculate its position and size at the pixel level, I prefer to animate a view's transform.scale with a good, simple addition, and the former is painful. Keep it simple.
It's time to set some key properties.
alertView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"alert_box"]];alertView.alpha0.0f;alertView.transform = CGAffineTransformMakeScale(1.21.2);alertView.layer.cornerRadius10;
In this code we have done four things:
- Set the BackgroundColor property to a picture, which is the picture I created that looks like a nice, simple view of the warning box.
- Set Alpha to 0 so that the warning box is not immediately visible until we want it to animate into.
- By
CGAffineTransformMakeScale() simply manipulating the scale value in the transform matrix, the function sets its Transform property to make the scale larger.
- The fillet is formed by setting the Cornerradius property of the view layer.
Let's add a bit of shading to it to complete the configuration of our warning box.
alertview . Layer .shadowcolor = [Uicolor Blackcolor] Alertview.layer .shadowoffset = Cgsizemake (0 , 5 ) Alertview.layer .shadowopacity = Span class= "Hljs-number" >0.3 f Alertview.layer .shadowradius = Span class= "Hljs-number" >10.0 f [Self.window Addsubview:alertview]
If I turn the alpha value back to 1.0 and remove the scaled-up transform and then take a screenshot, that's what it looks like.
Motion Design for IOS (26)