How to increase the height of a button using animation? - blackberry

Could someone let me know how to animate how to increase the height of a button?
I can increase the height of a button on the click of another button
Page {
Container {
Button {
id: btn2
text: "button2"
onClicked: {
btn1.maxHeight = 500
btn1.minHeight = 500
}
}
ImageButton {
id: btn1
defaultImageSource: "asset:///image.png"
}
}
}
But how do I animate the button increasing in height?
Thanks

Related

iOS: Expand cells when clicked on it

I have a cell with a label and a button if I click the button the height of the cell should increase and an image should get visible.
I set up autolayout with a height constraint for the image that I change, when the button is clicked.
The constraint that I use on init is displayed correctly (e.g. if I set the constant to 0 or 200). But if I change the constant in the button action, nothing happens.
Here is the logic for the constraint
func toggleImageHeight(){
cellIsExpanded = !cellIsExpanded
self.imageHeightConstraint.constant = self.cellIsExpanded ? 200 : 0
UIView.animate(withDuration: 2) {
self.layoutIfNeeded()
}
}
Your code is not proper. please try this.
self.imageHeightConstraint.constant = self.cellIsExpanded ? 200 : 0
UIView.animate(withDuration: 2) {
self.layoutIfNeeded()
}
this will work.

Increase uitablview height while run time to content entire content

I created an app with Swift 3 and Xcode 8.1. I have a UITableview and a UIView above it that shows and hides by clicking on a button in it. When the UIView appears, the last cell of UITableview does not show completely.
I use following code in button:
func filterShowHide ()
{
if !isShown
{
filterImage.image = UIImage(named: "ME-Filter-re")
self.filterView.isHidden = false
self.tableViewTop.constant = 0
// tableViewHeight.constant = tableViewHeight.constant * 1.5
isShown = true
}
else
{
filterImage.image = UIImage(named: "ME-Filter")
self.tableViewTop.constant = -(self.HeaderView.frame.height) + self.filterBTN.frame.size.height
self.filterView.isHidden = true
isShown = false
// tableViewHeight.constant = tableViewHeight.constant / 1.5
}
UIView.animate(withDuration: 0.25) {
self.view.layoutIfNeeded()
}
}
For more details here's the screenshot of:
Before clicking and After clicking
How can I show the last cell completely?
I think the problem is your tableview height is still the same and it gets pushed down as you update the top constraint.
You should set the table view bottom constraint to bottom of its super view or you can update tableView.contentInset.top with the values you are using for self.tableViewTop.constant

Increasing size of button every time it is pressed on Swift

I would like to know how to increase the size of a button every time it is pressed. I'm trying to make a simple game where 2 players using 1 phone press on their button located on opposite sides of the screen. Their button gets bigger the more it is clicked, causing the other players button to decrease in size. I have both buttons taking half the screen right now, but I'm having difficulty figuring out how to increase the size of a button as it is clicked.
This will make the frame of your button bigger, each time it is tapped.
#IBAction func buttonTapped(sender: AnyObject) {
let button = sender as! UIButton
//change the frame every time it is tapped
let increaseValue : CGFloat = 5.0
let newFrame = CGRectMake(b.frame.origin.x, b.frame.origin.y, b.frame.size.width + increaseValue, b.frame.size.width + increaseValue)
b.frame = frame
self.view.layoutSubviews() //update the button frame
}
If it is in the storyboard, connect the width and height constraints to your code. Then when your button is pressed, increase it.
#IBAction func buttonPressed(sender: AnyObject) {
widthConstraint.constant += 10
heightConstraint.constant += 10
self.view.layoutIfNeeded()
}

Animate PickerView Height Swift

I'm attempting to animate a UIDatePicker as I would animate a UIView, by changing the height constraint constant and animating it. But in UIDatePicker this doesn't work, everything around it animates, but the height instantly changes.
private func increasePicker() {
pickerHeight.constant = 200
UIView.animateWithDuration(0.2) {
self.view.layoutIfNeeded()
}
}
What's is the right way to do this? Thanks!
You can try this code.
private func increasePicker()
{
pickerHeight.constant = 200
UIView.animateWithDuration(0.2) {
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
}
}

Sliding a UIView down and then back up

I have a UIView that is will slide down on button tap and then slide back up on another button tap. It slides down perfectly, but when I try to hit the contract button, I can't click it, but it does click a collection view cell that is underneath the view. I can't figure out why it slides down properly but it doesn't function how I expect. Thanks a lot!
#IBAction func onExpandButtonPressed(sender: UIButton) {
let xPosition = expandingView.frame.origin.x
//View will slide to 40 px higher bottom of the screen
let yPosition = expandingView.frame.maxY - 40
let height = expandingView.frame.size.height
let width = expandingView.frame.size.width
UIView.animateWithDuration(0.5, animations: {
self.expandingView.frame = CGRectMake(xPosition, yPosition, height, width)
self.expandButton.hidden = true
self.contractButton.hidden = false
})
}
#IBAction func onContractButtonPressed(sender: UIButton) {
let xPosition = expandingView.frame.origin.x
let yPosition = expandingView.frame.origin.y
let height = expandingView.frame.size.height
let width = expandingView.frame.size.width
UIView.animateWithDuration(1.0, animations: {
self.expandingView.frame = CGRectMake(xPosition, yPosition, height, width)
self.expandButton.hidden = false
self.contractButton.hidden = true
})
}
Perhaps it's because the view has slid over the button. So try to use the following inside the button action that will slide over the non-working button:
self.view.bringSubViewToFront(buttonName)
If you put an NSLog inside your button Action, it can help determine if the function is being called.

Resources