How to make a popup window with an image SWIFT - ios

I was wondering how to make a popup window similar to this example:
The origin window is full of buttons that when is selected will then pull up the image I desire to use.

I would simply create a reusable UIView component and everything you need as a subview, such as a UIImageView for your image, a UILabel or a UIButton in the top right. Here is the process to show it:
Create a UIView that takes up the full screen, make it black, and maybe 0.5 alpha.
Create another UIView which is your primary pop-up view, make it slightly smaller than the previous view, but make sure both of these views are subviews of the parent subview.
Add the desired elements on to the pop-up view as subviews, I would even suggest creating a UIView subclass if you plan to use this a lot.
To present the pop-up, make sure both views are set to hidden = true when created and so that when a button is selected, you can set them to hidden = false
If you would like them to be animated, simply start them off with alpha = 0.0 and use something like UIView's animateWithDuration and set the pop-up view to alpha = 1.0
There is a lot of little details you can change to cater to your needs, but this is the basic structure on how to accomplish your goal.
Check out UIView animation methods here.

Related

How to Do this UI set revealing animation in swift

I am new to iOS development. Currently I'm developing a part from my previous Android app for learning purpose. I want to do following animation. I don't know a proper name for the animation so check below gif.
I have both text label with text field inside stack view. Can some one share the code for this animation or post a helpful link?
For such a case, I would suggest to use a UIStackView (vertical) to be the container for the components in the scene. When working with stack views, you could easily get such an animation for free! For applying the desired animation, the simplest way is to implement the popular UIView animate(withDuration:animations:) and hide the desired view in its animations block parameter:
UIView.animate(withDuration: 1.0) {
self.viewToHide.isHidden = !self.viewToHide.isHidden
}
By following this approach, you would be able to create an animation -which is what are you looking for- like this:
Resource: Easy Animation with UIStackView.
Official Reference:
You could review Mysteries of Auto Layout, Part 1 Apple Session (at 00:12:22, it should contains the topic that you are asking about).
There are various ways you could handle that. Below is one way. (Note that Ahmad's suggestion of a stack view would be easier and cleaner.)
Place your views that you want to appear inside another view. I'll call this view a container view (although in this case I don't mean container view the way interface builder refers to a view that can hold a child view controller.) Set the clipsToBounds flag on the container view to true.
Add a height constraint to the container view.
Select the constraint and control drag into your source file to make an outlet to the constraint. Note the current height value of the height constraint.
Now change the height value to zero. This should cause the views inside the container view to disappear.
When you want to animate those controls into place use a UIView animation that contains a call to self.view.layoutIfNeeded(). Set the height constraint of the ContainerView to its nonzero value immediately before the call to UIView.animate(duration:animations:).

moving image behind label

I have an image on my view, which I add programmatically & and not through storyboards. The image gets animated to move up the screen. At one point it crosses paths with several buttons and labels, which contain important text that gets blocked by the image passing over them. I want the image to move under the labels and buttons so that the text remains visible. Based on this answer IPhone Interface Builder: Z-Index, Z-order of a button, image, ui element, etc?, I tried to use editor => arrange => sendToBack/sendToFront, however, I don't think this is having any effect because the image doesn't appear in the tree of elements in the storyboard. As noted, it gets added programmatically at a certain time. Is there a way to do this?
I believe you can use [view insertSubview:imageView atIndex:0] which will place it behind all other subviews. Depending on what other subviews you have, you may need to increase the index as it controls what is placed over what in the view (lower index will go behind higher index)
As in answer to this question: Difference between addSubview and insertSubview in UIView class
If you're using addSubview:, your view will be placed on top. To control it's depth use either insertSubview:atIndex: (at exact place from bottom) or insertSubview:aboveSubview: or insertSubview:belowSubview: (which places new view above/below another known object in view hierarchy).

Making an element an element display on top of the UIView border

I am trying to place a UIButton inbetween my popup view and the parent view.
I cant successfully do that by doing that [self.view addSubview:new];. My problem there is the border UIView can be seen across the UIButton .
I've tried [self.view.superview addSubview:new]; thinking that that would make it go away but it doesnt it still shows there.
I need to find a way to successfully place that button on top of everything (UIView border in this case).
I know I could do that if I insert the button from the parentView, but I want to handle all my subViews buttons within each subView, otherwise it everything will become messy very quickly.
Is there a way to do what I am trying to achieve?
According to Apple's CALayer documentation, borders always appear above subviews because they're drawn on another layer. The best solution is to create a background view to fake the border.
So instead, your popup view would have an orange background. It'd have another, slightly smaller subview directly over it with a white background, and then your button.
See this post for the implementation.

UIView drop shadow on only one other view

There are a lot of questions about how to draw a drop shadow for a view. But how can I have my view cast a shadow that is received only by one other view?
If view A is the view with the shadow and view B is the parent of A, you can set masksToBounds which is a property of B's layer to YES.
Contents of B and its subviews will not be shown outside of B. They will be clipped.
More detail here: What UIView layer.masksToBounds is doing if set to YES?
However, if you want the shadow drops on more complex scene, you might need to be a little more specific.
Make an app with a white background.
Make your view plus shadow.
Take a screen shot.
Use the screen shot in your original app.
Of course you could also make the picture on the fly in code, but that is a bit more challenging. In any case, it would be code you do not need in your final app.

Custom UIbutton down part does not recognize touchup inside

I created a custom UIbutton and placed it onto a view which shows certain information about a package.I want the whole area to be touchable as button that was my starting point.THe problem is that only the upper half of the custom button is touchable and the down part is ignored.I set the background color to a solid one and the frame seems to be ok.
UPDATE: If i add the same custom button to superview it seems to be ok but the coordinates are not right in this case.I need to convert the coordinates of the subview to super view.
After struggling so many hours i figured out that my outer frame was smaller than it was supposed to be.

Resources