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];
}