I am creating an iOS version of my app. I need a ad banner at the bottom of the app. The banner is just a web view which is showing content from our Server.
In Android app we have created the WebView in activity and shown the pages using fragments. We need the same feature in iOS too, but I am not able to find a proper tool to do it.
I just need a WebView Banner at the bottom of all the ViewControllers. Is there any way to create one WebView Object and add to every ViewController or do I need to create separate WebView for all the UIViewControllers?
You have 2 options for that;
Number-1
You can create just one UIWebViewController and shown it on any other objects and windows even keyboard. All you need is that you have to add your UIWebviewController object to subview of last object of your window like that;
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:yourWebViewController];
Number-2
Use Apple's iAd program. It'll handle that for you.
https://developer.apple.com/iad/
Thanks for the suggestion from tnylee, the ContainerView method worked for me.
I basically created a new UIViewController, added ContainerView at top taking all the space and added UIWebView in bottom. After adding few usual Constraints, I removed the segue to the Main View Controller (Since I had an extra Loading Screen in start.) and moved it to the new ContainerViewController.
Now I just need to add an embed segue from the ContainerView (Not from ViewController) to the Main View Controller.
Here's how this looks in storyboard -
Related
(I have read other questions and answers on this topic, but most are very old and do not relate to iOS 9 or 10.)
The app design calls for the top half of the display to always contain the same content. (An image being edited by the user.)
The bottom half of the display needs a UITableView. When a UITableViewCell is tapped, the bottom section needs to transition to a new UIViewController with slide-on animation, similar to how UINavigationController push segues work.
Problem: only the bottom view needs to transition to the new view controller(s), and back again. The upper half of the view hierarchy needs to remain unaffected. For this reason, I can't place everything inside a UINavigationController, and I can't have a UINavigationBar at the top of the screen.
Question: what approach should I take in such a situation, where I need only one UIView hierarchy to transition in push-segue fashion, but not anything else? Thanks.
Edited with Solution
Solution follows, for those following along at home.
Yes, you can actually use a UINavigationController for the bottom half.
If you are using Storyboards, the easiest way to do this is to use a container view for each part of the screen which you then can embed a UIViewController in for the top part and a UINavigationController in for the bottom part. If you are doing this programmatically, just add the view controllers as child view controllers to your app's initial view controller (see this answer for more info) which is essentially what the Storyboard will do for you automatically when using a container view.
As a child view controller, the UINavigationController will act independently from the top UIViewController and should behave as expected.
I recommend the programatic approach for the following reasons:
It helps you understand the inner workings of child/parent view controllers much better which will likely save you a significant amount of debugging time down the line.
It makes adding/removing/swapping child view controllers as simple as a few lines of code. Trying to do this with Storyboards is notoriously hacky and cumbersome.
It's much easier to keep track of changes using GIT (most mid-size/larger companies actually prohibit Storyboards for this very reason)
If you want change in part of the screen you can use container view. For details refer Swift - How to link two view controllers into one container view and switch between them using segmented control?
You can use multiple view in one view controller and can give animation like push or pop to show or hide it.
Second approach is you can use Container View which will give exact effect like navigation stack.
I am having a hard time understanding why you can put UIViews outside the UIViewController on the storyboard, and what the use case of it might be.
For instance, on the storyboard I can add UIToolbar, UIAcitivtyIndicator and UIProgressView that is outside of the UIViewController. Is this mean there is a way for you to reference those Views that are outside UIViewController and potentially display them somehow either programmatically or embed those like you would do with a ContainerView?
Yes, it absolutely is possible to do what you're describing!
When you add objects that are outside the view controller, they appear in what Apple calls the "Scene Dock". Apple has the following suggested usage for the scene dock:
If a view is not part of the main view hierarchy — such as a pop-up
menu — add the view to the scene dock. In a running app, the system adds
and removes these kind of views from the view hierarchy when they are
opened and closed.
The steps to make this work are below:
Open the storyboard.
Open the utilities area for the workspace window by clicking the
utilities button in the
toolbar.
In the utilities area, select the Object library by clicking the Object Library button in the library bar.
On the storyboard, select the scene to which you will add the extra view.
Drag a view class object from the object library into the the scene dock.
And importantly...
The added view is a part of the view controller. It will be
instantiated along with the rest of the views. You can attach the view
to a property of the view controller that has an IBOutlet. You can add
more than one view to the scene dock.
(These steps were originally copied from here - unfortunately this page seems to have been deleted by Apple at some point).
I am subclassing UIApplication to intercept and display touches in my TouchDisplay view. I would like to extend the Application, Window, Delegate or Main ViewController in order to keep my TouchDisplay view on top of all other views. As my and most other applications work, views and controllers are added and removed all the time. I figure the correct answer will be able to deal with these additions and removals and stil keep the TouchDisplay view on top.
Thanks for your help,
Joe
Here are a few approaches you could take for this:
If you're targeting iOS 5+ and iPad only, you can make a top-level view controller which has two contained view controllers. The first would be a view controller for your "TouchDisplay" view. The second would be the application's normal root view controller. (i.e. your existing main view controller; you'll need to set definesPresentationContext to YES on this view controller) Since you're writing the container view controller, you can order those two subviews however you like. There is a WWDC 2011 Talk on view controller containment that goes into great detail about this. This is the most "correct" approach IMHO, because it gives you a view controller for your TouchDisplay view, handles rotation and generally plays nice with others. (This only works on iPad, because on iPhone a new modal view always covers the full screen.)
A more straight-forward approach is to simply add your TouchView to your existing top-level UIWindow as a subview with addSubview:. Most applications don't actually remove the top-level view controller or add new top-level ones; they just present other view controllers from it. A view you add in the top-level window will stay above those. Of course, your app may not follow this rule, in which case you might try option #3 instead. This has rotation gotchas (your view will not auto-rotate when the device rotates, so you need to do this yourself.) You could also force your view back to top, say, on a 1-second timer, if you are having issues with other things covering it. This is also not as nice as option #1 because you don't get a UIViewController, just a UIView.
The most extreme approach is that you can create another UIWindow and give it a higher window level, such as UIWindowLevelAlert and put your TouchDisplay view in that. You can then make the window background transparent, and it will stay above your normal app content. There are lots of gotchas here, especially about auto-rotation and which window is the keyWindow (which is why you should use #1 or #2 instead if you can).
After some time I was able to get my app working. I have made an easy to use overlay that shows touch feedback over your existing application.
You can download the project here:
https://github.com/megaplow/FingerTracks/tree/master/FingerTracks
Happy coding,
Joe
I'm developing an iPad application and I need to create an UIView that is always on top in respect to other views.
A is the area (consider it as a sort of sidebar) where I need to create a UIViewController which view remains always on top. B, instead, is the content area where a UIViewController (with its view) can change: depending on several button actions (inside A's view), it's possible to remove the current visible content (in this case controller B and its view) and display other controllers (C, D, E, etc.) with theirs views.
I created all the elements for my application but I have problems to maintain A's view on top and, at the same time, implement the logic used to dinamcally change the content area. As requirements I need that A always overlaps B. In other words, a portion of B (the left part) is always under the area of A. B always extends the entire device screen.
Could you give me some advice?
I made two configurations but I have problem with them.
First Configuration
In the first one, I created an UIViewController for A (called SideBarController). I added SideBarController view to UIWindow (within the application delegate). Then I created an UIViewController for B (called HomeViewController) and I added it as a rootViewController for my application.
This solution could be a valid one because I can change the content area dinamically (setting a new rootViewController) through my application delegate but the SideBarController remains always under the current visble view.
Second Configuration
In the second one, I created an UIViewController (called MainViewController) and I added it as a rootViewController for my application. Then within MainViewController I created an UIViewController for A (called SideBarController) and I added SideBarController view to MainViewController. Then the content area has been filled creating an UIViewController for B (called HomeViewController) and adding it to MainViewController.
The sidebar remains always on top but I have difficulties to change dynamically the content area within MainViewController. How is it possible to access the content area and change it?
Note I'm aware about standard components on UIKit but I need to implements such a solution because of user specifications.
I would begin by trying to implement your sidebar in a UIPopoverController. It's designed pretty well for this kind of problem, and you can customize it extensively to meet your UI needs. If UIPopoverController causes you some kind of problem, I'd put the sidebar in its own UIWindow and float that over the main window.
EDIT
Personally I'd go for the popover myself since it's more built for this kind of issue. Another thought that comes to mind and I've used in the past is a UIView that you add to directly to the UIWindow ([view window] from any view will get you the main one). Remember, UIWindow is just a special kind of UIView. The problem with this and the UIWindow solution is that you will have to do your own rotation logic which can be trickier than it sounds if you have autorotations. UIPopoverController handles all this very cleanly and automatically if you can use it.
If you pursue UIWindow see the Windows section of the View Programming Guide: http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingWindows/CreatingWindows.html
Basically this is my situation and don't want to use splitview.
I've a viewbased app, on a side of the main view i've to show a viewcontroller subclass but i don't know how to do it.
Something like this:
Even though Apple doesn't recommend it (at least on the iPhone), you can always access the view controller's view and manually add it. Like this (in MainViewController.m):
[self.view addSubView:self.secondaryViewController.view];