To achieve this function, you should first install the window-based application template I mentioned in the previous section:
Tutorial: http://blog.csdn.net/itachi85/article/details/7706549
Next, we will create a window-based application template.
Create an objetctive-C class file named hypnosisview:
Hypnosisview. h:
#import <Foundation/Foundation.h>@interface HypnosisView : UIView{ }@end
Hypnosisview. M:
In this file, we have added a concentric circle graph.
# Import "hypnosisview. H "@ implementation hypnosisview-(void) drawrect :( cgrect) rect {// obtain the drawing area cgrect bounds = [self bounds]; // calculate the center point cgpoint center; center. X = bounds. origin. X + bounds. size. width/2.0; center. y = bounds. origin. Y + bounds. size. height/2.0; // The distance from the computing center point to the border angle float maxradius = hypot (bounds. size. width, bounds. size. height)/2.0; // obtain the context cgcontextref context = uigraphicsgetcurrentcontext () required for the drawing; // draw all the lines cgcontextsetlinewidth (context, 10) with the width of 10 points ); // set the line color to [[uicolor lightgraycolor] setstroke]; // draw a concentric circle for (float currentradius = maxradius; currentradius> 0; currentradius-= 20) {cgcontextaddarc (context, context, center. x, center. y, currentradius, 0.0, m_pi * 2.0, yes); cgcontextstrokepath (context);} nsstring * text = @ "Hi: I am henrymorgen. "; // obtain the font uifont * font = [uifont boldsystemfontofsize: 28]; // calculate the drawing position cgrect textrect; textrect. size = [text sizewithfont: font]; textrect. origin. X = center. x-textrect. size. width/2.0; textrect. origin. y = center. y-textrect. size. height/2.0; // set the fill color of the current context to black [[uicolor blackcolor] setfill]; [text drawinrect: textrect withfont: font];} @ end
Then we configure the proxy appdelegate. h:
#import <UIKit/UIKit.h>@class HypnosisView;@interface HypnosisterAppDelegate : NSObject <UIApplicationDelegate, UIScrollViewDelegate> { HypnosisView *view;}@property (nonatomic, retain) IBOutlet UIWindow *window;@end
Appdelegate. M:
In the proxy, we added scrollview and added the previous hypnosisview to scrollview.
# Import "hypnosisterappdelegate. H "# import" hypnosisview. H "@ implementation progress @ synthesize window = _ window;-(bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {cgrect wholewindow = [[self window] bounds]; uiscrollview * scrollview = [[uiscrollview alloc] initwithframe: wholewindow]; [[self window] addsubview: scrollview]; // set the View Size to twice the window size cgrect reallybigrect; reallybigrect. origin = cgpointzero; reallybigrect. size. width = wholewindow. size. width * 2.0; reallybigrect. size. height = wholewindow. size. height * 2.0; [scrollview setcontentsize: reallybigrect. size]; // center cgpoint offset in the uiscrollview object; offset. X = wholewindow. size. width * 0.5; offset. y = wholewindow. size. height * 0.5; [scrollview setcontentoffset: Offset]; // enable the zoom function [scrollview setminimumzoomscale: 0.5]; [scrollview setmaximumzoomscale: 5]; [scrollview setdelegate: Self]; // create view = [[hypnosisview alloc] initwithframe: reallybigrect]; [view setbackgroundcolor: [uicolor clearcolor]; [scrollview addsubview: View]; [scrollview release]; [[uiapplication sharedapplication] setstatusbarhidden: Yes withanimation: compatible]; [[self window] makekeyandvisible]; return yes;}-(uiview *) viewforzoominginscrollview :( uiscrollview *) scrollview {return view;}-(void) dealloc {[view release]; [_ window release]; [Super dealloc] ;}@ end
Finally, run the command to see the effect: