IOS study notes (8) uipageviewcontroller uiprogressview listening and responding to keyboard notifications

Source: Internet
Author: User

Enable paging using uipageviewcontroller

Create a program: file --> New --> new project --> page-based application template --> next --> Device Family (universal) --> next --> Create;

The dataviewcontroller class provides an instance of this class to users on every page of the Page View Controller. This class is a subclass of uiviewcontroller.

The modelcontroller class is only a subclass of nsobject that complies with the uipageviewcontrollerdatasource protocol. This class is the data resource class of the page view controller.

-(Void) pageviewcontroller :( uipageviewcontroller *) pageviewcontroller didfinishanimating :( bool) finished
Previusviewcontrollers :( nsarray *) previusviewcontrollers transitioncompleted :( bool) completed;

When the user changes from one page to the next or previous page, or when the user begins to regret the transition from one page to another, and revokes the return to the previous page, this method will be called. If you successfully jump to another page, transitioncompleted will be set to yes. If you cancel the jump on the way, it will be set to No.

-(Uipageviewcontrollerspinelocation) pageviewcontroller :( uipageviewcontroller *) pageviewcontroller spinelocationforinterfaceorientation :( uiinterfaceorientation) orientation;

This method is called when the device direction changes. You can use this method to set the position of the page primary key by returning a value of the uipageviewcontrollerspinelocation type:

Enum {
Uipageviewcontrollerspinelocationnone = 0, uipageviewcontrollerspinelocationmin = 1, uipageviewcontrollerspinelocationmid = 2, uipageviewcontrollerspinelocationmax = 3
};
Typedef nsinteger uipageviewcontrollerspinelocation;

This may be a bit complicated for you. Let me demonstrate it to you. If we use a uipageviewcontrollerspinelocationmin value, the page view will only provide one view to the user. When we switch to another new page, a new page will be provided to the user. However, when we set the spine for uipageviewcontrollerspinelocationmid, we need to provide two views at the same time. One is placed on the right and the other is placed on the middle. You can see an example of the Page View Controller in horizontal mode and set the spine of uipageviewcontrollerspinelocationmin. The spine is placed in the middle of two view controllers. Once you flip the page from the right to the left, this page

The plane stops on the left side, and a new view controller is displayed on the right side. The entire logical relationship is in the delegate method below, as shown in the following code:

-(Uipageviewcontrollerspinelocation) pageviewcontroller :( uipageviewcontroller *) pageviewcontroller spinelocationforinterfaceorientation :( uiinterfaceorientation) orientation;

Now we are talking about page controller delegation. What is the advantage of data resources? The data resources of a page view controller must comply with the uipageviewcontrollerdatasource protocol. Two important methods in the Protocol are:

-(Uiviewcontroller *)
Pageviewcontroller :( uipageviewcontroller *) pageviewcontroller viewcontrollerbeforeviewcontroller :( uiviewcontroller *) viewcontroller;

-(Uiviewcontroller *)
Pageviewcontroller :( uipageviewcontroller *) pageviewcontroller viewcontrollerafterviewcontroller :( uiviewcontroller *) viewcontroller;

When the Page View Controller already has a view controller on the screen and needs to know the next View Controller to be displayed, the first method is called. This event occurs when the user decides to flip the next page. When this view is being flipped and the Page View Controller wants to determine which view controller needs to be displayed, the second method is called.

Use uiprogressview to display the progress bar

@ Property (monatomic, strong) uiprogressview * progressview;

@ Synthesize progressview;

-(Void) viewdidload {

[Super viewdidload];

Self. View. backgroundcolor = [uicolor whitecolor];

Self. progressview = [[uiprogressview alloc] initwithprogressviewstyle: uiprogressviewstylebar];

Self. progressview. Center = self. View. Center;

Self. progressview. Progress = 0.5f;

[Self. View addsubview: Self. progressview];

}

-(Void) viewdidunload {

[Super viewdidunload];

Self. progressview = nil;

}

It is very easy to create a progress view. Note that the progress can be correctly displayed, because the progress view's progress attribute value must be between + 0 and 1.0, assume that you have 30 tasks to be monitored and have completed 20 tasks, you need to specify the following equation to indicate the progress:

Self. progressview. Progress = 20366f/30366f;

Note: floating point numbers must be used here. If the integer 20/30 is used, the value is 0;

Listen to and respond to keyboard notifications

Uikeyboardwillshownotification // This notification is triggered when the keyboard is about to be displayed, including the information library.

Uikeyboarddidshownotification // This notification will be sent when the keyboard is displayed on the screen

Uikeyboardwillhidenotification // This notification is sent when the keyboard is to be removed from the screen. The notification contains the user information library, which contains a variety of detailed information about the keyboard information, animation, animation duration, and so on when the keyboard is hidden.

Uikeyboarddidhidenotification // This notification will be sent when the keyboard is completely hidden

Uikeyboardanimationcurveuserinfokey // specifies the animation type to display and hide the keyboard. This keyword contains an nsnumber value, which contains an nsuinteger unsigned integer.

Uikeyboardanimationdurationuserinfokey // specifies the time used by the keyboard to display and hide the animation. This includes an nsnumber value, which contains a double-byte value.

Uikeyboardframebeginuserinfokey

This key value specifies the frame of the keyboard before animation. If the keyboard is to be displayed, pass the frame to the animation before the display. If the keyboard is displayed and is about to be hidden, the frame will be passed to the hidden animation before the keyboard disappears. This key contains a cgrect type value.

Uikeyboardframeenduserinfokey

This key value specifies the keyboard frame after the animation is completed. If the keyboard is about to be displayed, the frame will be completely displayed on the keyboard and passed to the keyboard .. If the keyboard is fully displayed and is to be hidden, the frame will be passed to the keyboard after it is completely hidden. This key-value package contains a cgrect value.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.