Expanding UiView Animation - ios

I am trying to implement the following animation in my swift iOS app. There is currently a UIView at the bottom of my screen with the following properties :
let containerView : UIView = {
let this = UIView(frame: CGRectMake(0,0, 600,150))
this.backgroundColor = UIColor.clearColor()
this.layer.cornerRadius = 5
this.layer.borderColor = UIColor(red: (69/255.0), green: (209/255.0), blue: (153/255.0), alpha: 1.0).CGColor
this.layer.borderWidth = 0.5
return this
}()
Inside, there is an imageView, a couple buttons and other components. The containerView also has a blur effect implemented on it. When the user presses on it, I want the view to move upwards until it reaches the top of the screen. At the same time I want the borders to be drawn, to fill the whole screen, as shown in the outline below. I also want to apply the blur effect as an animation along with the border to the whole screen. Finally, when this animation is finished, I want my collectionView to fade into the space which has been created within the expanded view. I have next to zero experience with animating views in Swift, however these are the ideas which I had :
Apply a movement animation which moves the top of the view from the current position to the top of the screen.
During this process, gradually fade in the expanded view so that it appears as if the view itself is expanding.
Finally, when both animations complete, fade in the collectionView (this should be the easiest part).
However, I'm not sure if my way of thinking is correct, particularly when it comes to drawing the borders and background dynamically doing the animation. I am looking for some advice on how to approach this problem.

Take outlet of heightConstraint of the view which you want to animate.
Make heightConstraint.constant = 0 initially.
On click do something like this.
UIView.animateWithDuration(0.3) {
self.heightConstraint.constant = YOURMAXVALUE
// perform fade in out tasks here
self.view.setNeedsUpdateConstraints()
self.view.layoutIfNeeded()
};
or you can do this with topConstriant also..
Initially set topConstaint such that view will go down.
And then animate like this to see effects

Related

UIStackView subview contents visible during hiding animation

I am using a UIStackView for my layout. In that stack view, when I press a button I want to hide one of the subviews. That subview contains a couple buttons and a label. My issue is that during the hide animation, the buttons and label are visible until the vertical space from the subview is fully animated away.
Is there something I can do so that when I call subview.isHidden = true, the subview`s contents hide immediately at the beginning of the animation instead of at the very end of the animation?
use a custom stackView class. Use IBOutlets in the class to reference the buttons/text and write a function that hides your outlets when self.isHidden = true. Let me know if you need more explanation.
Besides hiding the buttons and content view with an animation you could try changing the background color from clear on the views inside the stackview to the same color as the background on your view. This still might not look great but it would be better.
Obviously animation would be something like the code below but give background color on your content views in the stackview a shot.
UIView.animate(withDuration: 0.1, animations: {
//yourContentHoldingView.alpha = 0
})

Make a UIView with a blurred view as borderColor

I need to create a UIView with a blurred view as borderColor.
How can I get that to work?
I have attached a sample image as an example of my requirement.
Thanks
I don't think the border of a UITextField has a fading property, or anything similar. However, with a bit of work, you can accomplish what you need:
1) Download/acquire a background image that has the border you want. It can be rectangular. Add it to your project.
2) In IB, set the BorderStyle of you TextView to None, the BackgroundImage to the image you added, and add an outlet to your UIViewController class.
3) Add the following code to your viewDidLoad. Replace with the name of your IBOutlet:
<textField>.layer.cornerRadius =5.0
This should give you a UITextField with rounded corners and your background image. You may have to play around with your image and the cornerRadius values to get exactly what you want, but the code should work.
Use my code its work perfectly. Textviewview is my One UIView and inside it one textfield and one UIImageview i use.
Textviewview.layer.cornerRadius = 25.0
Textviewview.layer.shadowColor = UIColor(white: 0.0, alpha: 0.5).CGColor
Textviewview.layer.shadowOffset = CGSizeMake(0.0, 0.0)
Textviewview.layer.shadowOpacity = 1.0
Textviewview.layer.shadowRadius = 6.0

How to make an SKView's background color clear

Hey i have a SubView that is a SKView and its on my controllers main view which is also an skview. So basically the subView-SkView is on the scene perfectly but the square frame of the subview skview stays like a fogy grey/smokey color. The only way i can get the fogy/smokey color off is by putting the alpha of the subview to 0.0 or a really lower number. By the way things to know but probably dont matter is. The subview doesn't have any nodes in it or attached to it. Also it is not apart of a SKScene. It is just the view. I don't know if any of that matters. But here the code below.
class Scene1: SKScene {
override func didMoveToView(view: SKView) {
super.didMoveToView(view)
var sub = SKView()
sub = SKView(frame: CGRectMake(self.view!.bounds.width / 1.5, self.view!.bounds.height / 2, self.view!.bounds.width / 3, self.view!.bounds.height / 2))
sub.alpha = 0.5
sub.allowsTransparency = true
sub.opaque = true
sub.backgroundColor = SKColor.clearColor().colorWithAlphaComponent(0.0)
view.addSubview(sub)
}
}
the white greyness at the bottom of the screen is the subview and this is at the alpha of 0.5
The only thing thats works is changing the alpha other than that the whole subview is covered in a square of smokey fog grey. I wonder if i put an SKNode on the subview will the whole subview frame not be a fogy/grey/smokey color any more. Or do i have to attach the subview to a SKScene. I just dont get why the overall subview frame color want change
As described in this SO question, setting the background colour of an SKView has no effect. You need to add a transparent SKScene to your view to make the whole thing transparent.

Avoid status bar transparency while animating

I got the viewController with 2 elements:
view with labels and buttons
tableView
I'm getting the following animation by changing view's height constraint from 170 to 0 and than animating view.layoutIfNeeded() and tableView.layoutIfNeeded().
My goal is to hide menu when content offset of the tableView reaches some value.
This works fine, except I got an overlay of status bar over the moving content from my view. Are there any options to add a sublayer to status bar not to be transparent? Or any other suggestions?
Thanks!
Create a view, put it where the status bar will be, and set its background color to which ever color you require. For example:
let statusBarView = UIView(frame: UIApplication.sharedApplication().statusBarFrame)
statusBarView.backgroundColor = UIColor.blackColor()
view.addSubview(statusBarView)
Or, set the content edge inset by (20.0, 0.0, 0.0, 0.0), which I would agree is a much more elegant solution, as suggested by #holex in the comments

Draw border "within" UIViewController

I need to draw a visible border that goes around the edge of the screen within my view controller. I tried setting the view's borderWidth and borderColor, but nothing appeared on the screen. How would I accomplish this?
I tried the following code and it worked.
self.view.layer.borderColor = UIColor.orangeColor().CGColor
self.view.layer.borderWidth = 3

Resources