ios - Present UIWebview on top on currently displayed view controller -


i'm trying modally display uiwebview on top of displayed view controller. code popup webview lives in static library , has no idea view controller hierarchy of app lives in. code below works test cases, not sure if work possible view controller hierarchies.

uiviewcontroller *rootviewcontroller = [[[uiapplication sharedapplication] keywindow] rootviewcontroller]; uiviewcontroller *presentedvc = [rootviewcontroller presentedviewcontroller]; if (presentedvc) {     // have modally displayed viewcontroller on top of rootviewcontroller.     if (!presentedvc.isbeingpresented) {     [presentedvc presentviewcontroller:vc animated:yes completion:^{         //     }]; } else {     rootviewcontroller presentviewcontroller:vc animated:yes completion:^{         //     }]; } 

does presentedviewcontroller give visible view controller?

if want display uiwebview modally on top of whatever view controller displayed in app, don't need "topmost" one. getting root view controller suffice. time whenever want present view on top of else. need reference root view controller in library:

self.rootvc = [[[[uiapplication sharedapplication] delegate] window] rootviewcontroller]; 

having reference have 2 options now:

the first 1 use uiviewcontroller's method presentviewcontroller:animated:completion: display view controller contain uiwebview

the second option fake modal view controller adding subview covers entire screen, has (semi)transparent background, , contains view want display "modally". here example:

@interface fakemodalview : uiview // *.h file  @property (nonatomic, retain) uiwebview *webview; @property (nonatomic, retain) uiview *background; // cover entire screen  -(void)show; // show fake modal view -(void)close; // close fake modal view  @end  @interface fakemodalview () // *.m file  @property (nonatomic, retain) uiviewcontroller *rootvc;   @end  @implementation fakeviewcontroller @synthesize webview = _webview; @synthesize background = _background; @synthesize rootvc = _rootvc;  -(id)init {     self = [super init];     if (self) {          [self setbackgroundcolor: [uicolor clearcolor]];          _rootvc = self.rootvc = [[[[[uiapplication sharedapplication] delegate] window] rootviewcontroller] retain];         self.frame = _rootvc.view.bounds; // make view same size application          _background = [[uiview alloc] initwithframe:self.bounds];         [_background setbackgroundcolor:[uicolor blackcolor]];         [_background setopaque:no];         [_background setalpha:0.7]; // make background semi-transparent          _webview = [[uiwebview alloc] initwithframe:cgrectmake(the_position_you_want_it_in)];          [self addsubview:_background]; // add background         [self addsubview:_webview]; // add web view on top of     }     return self; }  -(void)dealloc { // remember release      [_webview release];     [_background release];     [_rootvc release];      [super dealloc]; }  -(void)show {      [self.rootvc.view addsubview:self]; // show fake modal view }  -(void)close {      [self removefromsuperview]; // hide fake modal view }  @end 

if have other questions let me know.

hope helps!


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -