I've got an iPad app with a “drawer” table displayed in a popover. The user can tap-and-hold on an item in the drawer to drag that item out of it and into my main view. That part works fine; unfortunately, the view being dragged appears under the popover, and is too small to be visible until it's dragged out from underneath it. If I add the view as a subview of the view controller in the popover, it gets clipped by the popover's frame, and as I can't access the UIPopoverController's view, I can't disable its layer's masksToBounds—and that probably wouldn't be a great idea anyway. I suspect that I could use an additional UIWindow with a high windowLevel value to force the dragged view to appear on top of the popover, but this seems like overkill. Is there a better solution?
Got it. UIWindow works fine. Code:
// when drag starts
draggingView = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,100,100)];
draggingView.windowLevel = UIWindowLevelAlert;
draggingView.center = [gestureRecognizer locationInView:self.view.window];
[draggingView makeKeyAndVisible];
// when drag ends
[draggingView release];
draggingView = nil;
Adding the Swift Version:
let windows: [UIWindow] = UIApplication.shared.windows
let firstWindow: UIWindow = windows[0]
firstWindow.addSubview(loadingView)
firstWindow.bringSubview(toFront: loadingView)
EDIT to admin: thanks for the review – deleted my other answer in duplicate How to show a UIView OVER a UIPopoverController
Related
I have one xib in portrait view and one in landscape view. I am changing xib in rotation like this:
[[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:#"%#_landscape", NSStringFromClass([self class])]
owner: self
options: nil];
It's working fine but if I open one view as a subview in the current view then it disappears. For example, on any button click I am adding one view (like a popover) in the current view, but in the rotation subview it disappears. How can I solve this issue?
Any help is appreciated.
You need to make property for that view and when ever you perform rotation you need to re add same view on the top of rest of the views by simply use addSubview function of UIView.
Instead of changing views for different mode,use autoresizing.It will let you work on single view autoResize when rotate.Here is fine example you can learn.
AutoResizing
I think this is not a good approach. You should take one UIViewController with XIB. Now take two views(one for landscape and another for portrait connect it with outlets) outside ViewController's view, and on at rotation time
yourCurrentView = landscapeView/portraitView;
[self.view addSubview:yourCurrentView];
and set it [self.view sendSubviewToBack:yourCurrentView]; //because what ever view added dynamically on self.view remains on top, now your view which was added always show at every mode.
I hope it will help you.
I haven't been able to find anything on this and feel it likely isn't possible in a simple manner.
Can I have a view, such a loading bar for example which constantly sits over every other view controller until I choose to dismiss it but at the same time any underlying view can still be interacted with? Sort of acting like a system view. Be persistent when presenting new view controllers and all.
Thanks.
Add it as a subview of your window. Like this:
UIView *myView = ...
[self.window addSubview:myView];
Rather than adding it to the window, as #JackyBoy suggests, add it to the window's rootViewController's view. That will rotate along with the device. If you just add it to the window, you may have problems with rotation.
UIView *myView = ...
[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:myView];
I am trying to make some kind of popup view when a button i pressed on the iPhone. And it would be nice if I could manage that popup view with a ViewController. I have found out that the UIPopoverController could have been the solution, but it seems that it only works on the iPad...
But anyway, are there any similar solutions for the iPhone?
I am using storyboard
Check out these repos on Github:
https://github.com/werner77/WEPopover
https://github.com/50pixels/FPPopover
Create a separate view controller and resize its xib file and make it look like a popup.
Then ADD this view controller as a subview, and also add it as childController too.
[self addChildViewController:self.popOverViewController];
[self.view addSubview:self.popOverViewController.view];
Now Make it hidden initially.
self.popOverViewController.view.hidden = YES;
If a user taps on Button then using fade in & Fade out animation you can hide/unhide it.
I can tell you how to fade in and fade out if you want to know it further, I hope you can do it easily.
In interface builder make a UIView size of the screen and then make another in that Uiview with the style, size and the such for your pop over. Make its class, hook everything together.
CustomPopUpView *view = [[CustomPopUpView alloc] initWithFrame.....]
Add this all to your UIViewController with
[self.view addsubview:view]
Then attach a tapGestureRecognizer to the back view that animates the whole view off screen when tapped. So now if they click off your pop over view it close it will animates it off screen.
Hope this makes sense.
BooRanger
I have an application with a navigation bar and a tab bar. A user can navigate to a view which displays images in a scroll view. I'd like to have the same behavior as the iPhone photo app: Nav bar at the top, tool bar at the bottom, which will hide or show based upon a tap.
I'm moving my view to the window object in order to achieve full screen mode. This works fine:
myView = [self.view retain];
self.view = nil;
[window addSubview:myView];
But when I want to redisplay the Nav & tool bar, I run into a problem. The bars show fine, but the view is empty, and I can't seem to add any content to the view:
[myView removeFromSuperview];
self.view = myView;
I got a lot of good info from this post
but can't quite get the right combination.
By simply setting the controller's view, you aren't adding it as a subview to anything else, so it will never appear.
Moving views around like this can get a little tricky. I recommend that you not move the view from one to the other, but instead have two UIViews. Add second UIView to the window's subview and set it to hidden=YES initially. When you want to show it, set the image for the UIImageView, and then set the hidden property to NO.
what's wrong with just using setNavigationBarHidden: animated: and setToolbarHidden:animated:?
I have UITabBarController with 2 tabs. One resizes just fine, when StatusBar size changes (emulator "Toggle In-Call Status Bar" menu item). The other one doesn't.
The problematic tab item contains a static view, which dynamically loads one or another view depending on certain things. While getting this setup working I discovered that main tab view did NOT automagically send e.g. viewWillAppear and viewWillDisappear messages to my dynamic subviews.
Apple docs explained this was because dynamically added views were not recognized by the system.
#interface MyTabViewController : UIViewController
{
UIView *mainView;
FirstViewController *aController;
SecondViewController *bController;
}
...
if (index == 0)
{
self.aController = [[FirstViewController alloc]
initWithNibName:#"FirstViewController" bundle:nil];
[self.mainView addSubview:aController.view];
[self.aController viewWillAppear:YES];
}
How can I get StatusBar size changed event into my dynamic subviews? The "didChangeStatusBarFrame" doesn't work, as documented elsewhere.
Have you taken a look at this question?
Also, can we see your App Delegate code using application:didChangeStatusBarFrame:?
You could program a resize yourself, but usually this is done by using "auto resizing masks". (UIView has a property autoresizingMask).
I'm not sure about it but since your were adding those views programmatically maybe you forgot to set the autoresize mask. Without it the view won't resize automatically when the status bar frame changes.
[newView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
I hope it helps.