iOS 7 Weather App Expand/Collapse Transition

iOS 7 Weather app expand/collapse transition

User antol put some effort into replicating the behavior:

https://github.com/Antol/APPaginalTableView

But note that APPaginalTableView doesn't have a separate controller for the expanded pages.

You can see it in action here:
https://www.youtube.com/watch?v=X1YvxDMr0yA

iOS animating UILabel expand

You can animate number of lines. It changes the intrinsicSize of the UILabel. You need to call layoutIfNeeded inside your animation block on the view containing the UILabel. Here I attach a tap gesture to the table to toggle it between having 0 (as many as you want) lines and 1 line.

 func tapLabel(tapGesture: UITapGestureRecognizer)
{
if let label = tapGesture.view as? UILabel {
label.numberOfLines = label.numberOfLines == 0 ? 1 : 0
UIView.animateWithDuration(0.5) {
label.superview?.layoutIfNeeded()
}
}
}

Sample Image

How to pause and resume UIView.animateWithDuration

2 functions to pause and resume animation, I take from here and convert to Swift.

func pauseLayer(layer: CALayer) {
let pausedTime: CFTimeInterval = layer.convertTime(CACurrentMediaTime(), from: nil)
layer.speed = 0.0
layer.timeOffset = pausedTime
}

func resumeLayer(layer: CALayer) {
let pausedTime: CFTimeInterval = layer.timeOffset
layer.speed = 1.0
layer.timeOffset = 0.0
layer.beginTime = 0.0
let timeSincePause: CFTimeInterval = layer.convertTime(CACurrentMediaTime(), from: nil) - pausedTime
layer.beginTime = timeSincePause
}

I have a button to pause or resume the animation which is initiated in viewDidLoad:

var pause = false
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
UIView.animate(withDuration: 10.5) {
self.image.transform = CGAffineTransformMakeTranslation(0.0, 200)
}
}

@IBAction func changeState() {
let layer = image.layer
pause = !pause
if pause {
pauseLayer(layer)
} else {
resumeLayer(layer)
}
}

Appearance of table cells when deleting

It turned out that somebody else had already answered this in a slightly different question:

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}

UITableViewCell expand on click

Implement heightForRowAtIndexPath to calculate the right height. Then in the code for your button, force the table to reevaluate each cell's height with beginUpdates plus endUpdates:

[self.tableView beginUpdates];
[self.tableView endUpdates];

Changes to the tableview cells' heights will automatically be calculated with heightForRowAtIndexPath and the changes will be animated too.

In fact, instead of a button on your cell that does this, you might even just make selecting the cell do this in didSelectRowAtIndexPath.



Related Topics



Leave a reply



Submit