I'm writing an UIPageViewController based application over which view I placed a subview:
[self.view addSubview:fontViewController.view];
This view fade in and out when I tap on the center of the main view (the pageviewcontroller one). When this view is shown, I don't want that disappears when I change the page. I think that this subview should be added to a layer over the main view and not to the view itself. Am I wrong? If not, how can I do that?
What is the parent of the main view?
In some cases this might work:
[self.view.superview addSubview:fontViewController.view];
Related
I'm using a scroll view in the storyboard for one of my view controllers and I would like to know if there is a way to move the current view of the view controller down so that I can add things below.
I've seen that when tapping on CollectionView (which is at the bottom of my screen and extends below the view), the view on my viewcontroller seems to move down a bit to reveal more of the CollectionView, but not entirely. Is there a way that I can make the view go lower?
Change the size of viewController as shown in the image below:
Im creating an ios app using story board. I want to add a subview over the current viewcontroller. the current view controller should be fully covered from that sub view. But my problem is when I add the subview it appear under the navigation bar. I set is as
[self.view addSubview:mysubview];
How do I fully cover my view from that sub view
Since you want to cover the complete navigation controller, you can try this instead:
[self.navigationController.view addSubview:mysubview];
I want to place a UIView that will inform the user what is the status of the app. I want that view to be visible even if the user switches views, same thing as the UINavigationBar is always visible, but I don't want to use that bar, I would like to add another view that will show a message.
How can this be done? I can't add the view to the current view, because it will disappear, if the user changes views.
It should be added to the window? But how? I would then have to resize the views so that my new view can fit, but how?
Thanks.
Create a container view controller and set it as the rootViewController of the apps window.
Inside this container you have your status view, and you also resize the windows real rootViewController to take up the remaining space as a subview. If you are using a standard container view conrtoller (tab, navigation etc) as the root then you can use standard navigation methods and the status view will always be visible
There would be problems if you wanted to present modal views though, since these would go over the top of the status view
In your appDelegate.m add your view as subView of window.
UIView *mainBg = [[UIView alloc] init];
mainBg.frame = newframe;
[self.window addSubview:mainBg];
If you have a UINavigationController you can add your view to its view.
[self.navigationController.view addSubView:yourView];
Presenting modal views would cover the view, as stated in the other answer.
I've created a custom subclass of UIViewController that acts like a UINavigationController or a UITabBarController. Let's call it a ToolbarNavController. It has a toolbar at the bottom with controls for the user to move to a different content view.
I have two content views aside from the ToolbarNavController's view. Both are loaded from a nib and have their own controllers. The app starts out showing one of them. A button in the toolbar allows the user to switch between them.
When I add these views as subviews of the ToolbarNavController's views in viewDidLoad, they are correctly resized to fill the area between the status bar and the toolbar without overlap/underlap.
But when I try to lazy load the second view, adding it as a subview for the first time only when the user presses the toolbar button, iOS does not resize the view to account for the toolbar in its parent view, and it underlaps the toolbar which messes up my Autolayout constraints. Also, when I don't add the subview in viewDidLoad, if I put the device in landscape orientation before switching to the second view, it loads with a portrait orientation frame.
Bottom line: When inserting a subview in viewDidLoad, iOS sizes it correctly and manages autorotation for it. When inserting it later, I need to detect orientation set the frame myself. (And for some reason when I do this, autorotation kicks in again).
What is going on?
In viewDidLoad, the view is not yet layout for the resolution and interface orientation, and view properties are as they were in the interface designer. So, if you had a portrait view, that is how the initial properties of the view are set when going into viewDidLoad. When you add your view there, you add it to the XIB view. Later, iOS performs layout on the view hierarchy and thus resizes your inserted view as needed. But when adding your view at a later point, the view hierarchy has already been layout, so it is expected that the new view you are adding is also layout correctly.
Best practice is to calculate the size you need using the size of the view you are inserting into. For example, half the width of the containing view, or third the bounds, etc. This way it is independent on the orientation the interface is in.
I have two UIScrollViews that I move images between. The user can drag and forth between the scroll views. I am trying to animate the movement of the image from one scroll view to another. In -touchesMoved (handled in my UIViewController which has two custom UIScrollViews that intercept touch and sends to my UIViewController), I am trying to set the "center" of my UIImageView that is being moved. As it is moved, the image gets hidden behind the UIScrollView and not visible. How do I make it appear on top of the UIScrollView? I am able to handle the -touchesEnded properly by animating in the destination scroll view.
I am also confused about -convertPoint:fromView: usage in the iPhone Programming Guide (See Chapter 3, Event Handling). If the touch coordinates are in window coordinates, to change my view (UIImageView inside a UIScrollView which is inside a UIView and inside a window) center don't I have to use -convertPoint:toView:, i.e.,
imageView.center = [self.view.window convertPoint:currentTouchPosition toView:imageView];
What am I missing?
You can use the method - (void)bringSubviewToFront:(UIView *)view for making the image view the front most view.
Johan
It depends on how you structured your views. If both scrollviews and the imageview are at the same level, it should work. If the imageview is a subview of one of the scrollviews, you can try bringing the scrollview to the front. That way also the imageview will be drawn over the other scrollview.
Johan
I have a View Controller with two ScrollViews. Images are added as subviews. ScrollViews are already in the front. I tried bringing scrollview to the front and also imageview of the scrollview to the front. But somehow when i drag, the center of the image goes over my other scrollview2 which i also tried sending back. But does not seem to work. Here is what i do, in TouchesMove (inside a ViewController)
view= [[scrollView1 subviews] objectAtIndex:currentImageIndex];
[self.view bringSubviewToFront:scrollView1];
[scrollView1 bringSubviewToFront:view];
[self.view sendSubviewToBack:scrollView2];
scrollView1 and scrollView2 are two scrollviews that are part of the ViewController's view.
Does this make sense ?
thanks
mohan