[autoresizing case Objective-C language]

1. Autoresizing case

notify

1. Before introducing autoresizing, tell everyone that this is just an introduction, do not use this thing in the future, use autolayout

Another very important thing is that if you use autoresizing, you cannot use autolayout, and vice versa

notify

2. Let's look at a case, what kind of case is it, let's look at such a case,

Let's take a look at my requirements first:

1) Place four UIViews with a height and width of 100 at the four corners of the controller's view

2) Let these four UIViews always be displayed correctly at the four corners no matter what kind of screen they are on

We use autoresizing to achieve

Create a new project

notify
notify

Suppose, I open our controller

notify

Main.storyboard

notify

Check this, controller

Let's set it to 3.5 inches first

notify

Simulator changed to iPhone4S

notify

ok now is there a controller

Then, next, I want to be on the top of the controller, how to say, the northwest corner, the southwest corner, uh, the upper left corner, right?

Come, come, pay attention, did I put a View here?

notify

Put a View up

notify

The width and height of the View are both 100

notify

Ok, then, I set the background color of this View, yellow

notify

Then, is this View displayed in the upper left corner?

Ok, now this View is displayed in the upper left corner

Then, next, in the four corners, put four

Select it, hold down the option key, and drag

notify

is there one in the upper right corner

notify

Drag, there is one in the lower right corner,

drag

notify

Is there one in the lower left corner?

notify

In order to see clearly, each color is different

notify

OK, now this screen's

notify

Are there these four small squares on the four corners?

Come, at this time, we command + R, run it,

Everyone said, at this time, is there any problem?

Is this the way we set the frame before?

It's set up directly, it's set up directly, let's run it,

Under 3.5 inches, iPhone4S, see if the effect is correct or not,

notify

have a look

notify

At this time, doesn't it look very good

In the four corners of our top, bottom, left and right, it looks very good, that is to say, the case programs we were doing before, do they all have the same effect now, they look very good, but you have never tried those programs before us , hold down the command key + press the arrow key right

Is the screen turned to landscape?

notify

Press and hold command + arrow key right, is the screen horizontal

After the screen is changed to landscape, is it still the same effect?

What we want is that after the screen is turned into a horizontal screen, a yellow square is displayed in the upper left corner, a blue square is displayed in the upper right corner, a purple square is displayed in the lower left corner, and a red square is displayed in the lower right corner.

What we want is that regardless of whether the screen is vertical or horizontal, it is required to display squares of different colors at the four corners.

Because, the frame we use now is written to death, without setting the screen adaptation,

So, below you, the red square, what is its constant Y value,

notify

Is it 380, ah

When the screen becomes horizontal, the Y value is 380, does it go outside the screen?

notify

Can't you see it?

In this case, is there no screen adaptation, just a 4-inch screen, after I horizontally screen, is the effect wrong?

Well, I'm going to replace it with another screen and see if it's right

notify

Now iPhone4S, is it 3.5 inches?

I changed the simulator to iPhone5S, 4 inches,

Let's take a look at it under the 4-inch screen to see the effect and what effect it is

Is it very uncomfortable to preview in this way? Does it take a long time to wait every time?

Guess you like

Origin blog.csdn.net/madoca/article/details/132016443