"iOS feature implementation" uses Uidocumentinteractioncontroller to open and preview documents

Source: Internet
Author: User

iOS provides support for using other app preview files, which is document interaction Controller. In addition, iOS also supports file associations, allowing other programs to call your app to open some sort of file. And, starting with 4.2, the Quick look framework provides built-in printing for a variety of documents. You can refer to the Documentinteraction Controller class reference as well as the Quick Look Framework guide, as well as the Docinteraction sample program.
This paper discusses the use of document Interactioncontroller.
-, creating an instance
Documentinteraction controller uses a static method Interactioncontrollerwithurl to create an instance that uses a nsurl as an argument.
Code:
Nsurl *url=[nsurl Fileurlwithpath:path];
controller = [Uidocumentinteractioncontroller Interactioncontrollerwithurl:url];
Second, display the preview window
The document interaction Controller object pops up a full Screen preview window using the Presentpreviewanimated method.
Code:
BOOL B=[controller Presentpreviewanimated:yes];
Third, display menu
If you do not want to pop the preview window directly, you can display an option menu to the user, and the user chooses the appropriate action. Display menus can use the following methods:
–presentoptionsmenufromrect:inview:animated:
–presentoptionsmenufrombarbuttonitem:animated:
–presentopeninmenufromrect:inview:animated:
–presentopeninmenufrombarbuttonitem:animated:
These methods are similar, except that they show a different location. The following code demonstrates the use of one of these methods.
Code:
CGRect navrect = self.navigationController.navigationBar.frame;
Navrect.size = Cgsizemake (1500.0f, 40.0f);
[Controller Presentoptionsmenufromrect:navrect InView:self.view Animated:yes];
Iv. Use of Delegates
If you display a document interaction Controller, you will need to specify a delegate for the delegate property. Let the delegate tell Documentinteraction controller how to display.
Code:
Controller.delegate =self;
The delegate object needs to implement a series of delegate methods, most commonly including:
–documentinteractioncontrollerviewcontrollerforpreview:
–documentinteractioncontrollerviewforpreview:
–documentinteractioncontrollerrectforpreview:
These 3 methods are called in turn when the user clicks the "Quick View" menu.
Code:
-(uiviewcontroller*) Documentinteractioncontrollerviewcontrollerforpreview: (uidocumentinteractioncontroller*) Controller
{
return self;
}
-(uiview*) Documentinteractioncontrollerviewforpreview: (uidocumentinteractioncontroller*) controller
{
return self.view;
}
-(CGRect) Documentinteractioncontrollerrectforpreview: (uidocumentinteractioncontroller*) controller
{

return self.view.frame;
}
Call when the "Done" button is clicked on the preview window

-(void) Documentinteractioncontrollerdidendpreview: (uidocumentinteractioncontroller*) _controller
{
[_controller Autorelease];
}

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.