The following print screen shows my layout:
I have the main view , then a Top view and then a picture.
When I press on the picture, I want a semi transaprent black screen appearing on the entire view:
let scrennRect = UIScreen.mainScreen().bounds
let coverView = UIView(frame: scrennRect)
coverView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)
self.view.addSubview(coverView)
But I want my picture to stay on top of the coverView ?
Is there a way I can bring only the picture to be in front of the coverView ?
The problem is that your coverView and imageView have different super views.
That's why you cannot bring the imageView to the front.
In order to bring the imageView to the front you need to move it outside of the Top View so your View contains the Top view and the imageView.
Then, you can add the coverView to the main view, and bring the imageView to the front.
Another solution:
Place an image view inside the coverView at the exact same position.
This should do your work. Any view maintains a stack of its subviews.
self.view.addSubView(blackTransparentView);
self.view.bringSubViewToFront(myImageView);
Related
I want to ignore navigation bar and make full size view in navigation controller.
But the view is shown under the navigation bar.
Could I overlap navigation bar with black view?
I want to make like this picture
To achieve the given UI you should add the top view on window.To do so, First make an xib of top view. then add given code:
let frame = UIApplication.shared.keyWindow?.frame
let wrapper = UIView(frame: frame!)
wrapper.backgroundColor = UIColor.black.withAlphaComponent(0.35)
let objView = YourView() // Create your view object here.
objView.frame = wrapper.frame
objView.center = wrapper.center
wrapper.addSubview(objView)
UIApplication.shared.keyWindow?.addSubview(wrapper)
Set frame of YourView according to your requirement. wrapper makes your view transparent. You can make single view without wrapper. Use same code to add your view on window.
I'm trying to display a large button at the bottom of the screen, so that it appears above the toolbar.
Button Overlapping Toolbar
My first attempt at this works on the iPad, and on the iPhone in Landscape mode, but the button appears behind the toolbar in Portrait mode. So, this is probably related to the difference in rendering with the Split View Controller:
addButton.frame = CGRect(x:0, y:0, width:48, height:48)
addButton.setBackgroundImage(UIImage(named:"Button - Add"), for: .normal)
let topView = self.navigationController?.view
topView?.addSubview(addButton)
I don't want it to appear above all other view controllers, e.g. popovers and modal segues, so I can't place the button on the application's topmost window, i.e. the following doesn't give me the right result either:
let topView = UIApplication.shared.windows.first
topView?.addSubview(addButton)
The only solution that works for me is to add the button to the toolbar, but this isn't great because the touch zone for the button is clipped by the toolbar:
self.navigationController?.toolbar.addSubview(addButton)
let topView: UIView? = addButton.superview
So, does anyone know of a way to place a UIView or UIControl in a layer or view above the toolbar, but still on the active viewController?
My aim is to create a popup view right below a button once is clicked, this is the concept:
The way I prepared the storyboard is by using two different UIViewController. The main one contains the two buttons and, once clicked, I modally push the second UIViewController over the current context.
My question is: what's the best or properly way to create constrain in order to move the "Tapped" image right below the button?
The way I do this is to add a childcontroller to your first storyboard vc. Then adjust the frame of the container view in the storyboard, which I hope will be easier than programmatically adjusting frames.
Then be sure to change the class on top of the VC that Xcode created for you.
When the button is clicked get the the bottom position of it (it's y in frame + height) and send it to the popup , then set them as the top constraint of the imageView in popup in viewDidLayoutSubview
You can calculate the position of the overlay using the button's and the view's positions and dimensions. For example, the overlay's y can be the button's frame.maxY + constant.
let x = ...
let y = ...
let width = ...
let height = ...
let overlay = UIView(frame: CGRect(x: x, y: y, width: width, height: height))
view.addSubView(overlay)
The translucent black view can be added as a UIView with the same frame as the view of the VC and constrained to always be the same as the frame of the VC's view. Add this view first, before you add overlay.
I have 2 viewcontrollers.The first one should occupy major portion of the screen and second one should be at the bottom portion
How do i make the bottom viewcontroller slide up to occupy the entire screen
you can use addchildViewController method of UIViewController
basically when you want to show the other VC. do this in first
let vc = SecondVC()
self.addChildViewController(vc)
self.view.addSubView(vc.view)
//now set constraints or set the vc.view frame to whatever position you want
I'm trying to recreate google inbox's plus button on a UITableView
Here's the image:
I want to recreate the red plus button on the bottom right in a UITableView. I've got an image which is the red button and I've tried just dragging a button onto the storyboard, but it orbits around the contentView. I can't move it to the bottom right.
I also tried adding a transparent UIView as a subview of my table view like so:
let transparentView = UIView(frame: self.view.frame)
transparentView.alpha = 0
let plusButton = UIButton(frame: CGRectMake(50, 50, 50, 50))
plusButton.imageView?.image = UIImage(named: "plus")
transparentView.addSubview(plusButton)
self.view.addSubview(transparentView)
The view just doesn't show up. Not sure whats wrong. Any ideas?
You will have to position it in the superview of your table view:
o View Controller
|
\---o View
|
+---o Red Button
|
\---o Table View
Try using the side bar in Interface Builder to get your red button to the right place in the hierarchy. If you need to insert a parent view to your table view, try using Editor > Embed in > View