2015-01-07 24 views
6

Ich verfolge THIS Tutorial und erreichen, dass die Animation mit diesem Code:TableViewCell Animation in schnellen

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 
    cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1) 
    UIView.animateWithDuration(0.25, animations: { 
     cell.layer.transform = CATransform3DMakeScale(1,1,1) 
    }) 

} 

Aber ich möchte etwas in dieser Zelle Animation wie aktualisieren, wenn ich in Tableview Scrollen der Zelle wie (0.1,0.1,1) klein ist der Anfang und danach Skalen wie (1,1,1), aber ich möchte wie Bubble-Typ-Effekt wie es ist klein am Start nach, dass es bei seiner ursprünglichen Skala wie (1,1,1) kommt und man es zoom und wieder kommt es in seine ursprüngliche Skala wie (1,1,1).

bitte führen Sie mich, wie kann ich diese Animation erreichen?

EDIT:

habe ich versucht, diese aber es ist nicht diese Art von glatten und nicht genau, was ich will.

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 
    cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1) 
    UIView.animateWithDuration(0.3, animations: { 
     cell.layer.transform = CATransform3DMakeScale(1,1,1) 
    }) 
    UIView.animateWithDuration(1, animations: { 
     cell.layer.transform = CATransform3DMakeScale(2,2,2) 
    }) 
    UIView.animateWithDuration(0.3, animations: { 
     cell.layer.transform = CATransform3DMakeScale(1,1,1) 
    }) 

} 

Antwort

16

Was Sie brauchen, ist eine Leichtigkeit zurück Animation. Weitere Informationen finden Sie auf http://easings.net

Sie parametrische Animationen machen können diese Bibliothek mit https://github.com/jjackson26/JMJParametricAnimation/tree/master/JMJParametricAnimationDemo

Vorerst der Effekt, den Sie versuchen, grob zu tun mit dem Code unten getan. Sie müssen die Skalierungsanimation nacheinander ausführen. Die Art, wie Sie es getan haben, lässt alle Animationen zusammen starten.
Das Hinzufügen des nächsten Animationscodes in Abschlussblock startet es nach der Animation. Sie können die Timings weiter optimieren, um den gewünschten Effekt zu erzielen.

cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1) 
    UIView.animateWithDuration(0.3, animations: { 
     cell.layer.transform = CATransform3DMakeScale(1.05,1.05,1) 
     },completion: { finished in 
      UIView.animateWithDuration(0.1, animations: { 
       cell.layer.transform = CATransform3DMakeScale(1,1,1) 
      }) 
    }) 
+0

danke für die hilfe bro. –

+0

Ich habe den Code geändert, um es besser zu machen. – rakeshbs

+0

ok danke ...... –

7

Swift 3 Version funktioniert wie Charme!

cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1) 
    UIView.animate(withDuration: 0.3, animations: { 
     cell.layer.transform = CATransform3DMakeScale(1.05, 1.05, 1) 
    },completion: { finished in 
     UIView.animate(withDuration: 0.1, animations: { 
      cell.layer.transform = CATransform3DMakeScale(1, 1, 1) 
     }) 
    }) 
1

Verwenden Sie diesen Code Spiralzellen Animation in Ihrem Tableview

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) 
    //1. Setup the CATransform3D structure 
    var rotation = CATransform3DMakeRotation(CGFloat((90.0 * M_PI)/180), 0.0, 0.7, 0.4); 
    rotation.m34 = 1.0/-600 


    //2. Define the initial state (Before the animation) 
    cell.layer.shadowOffset = CGSize(width: 10.0, height: 10.0) 
    cell.alpha = 0; 

    cell.layer.transform = rotation; 
    cell.layer.anchorPoint = CGPoint(x: 0.0, y: 0.5) 


    //3. Define the final state (After the animation) and commit the animation 
    cell.layer.transform = rotation 
    UIView.animate(withDuration: 0.8, animations:{cell.layer.transform = CATransform3DIdentity}) 
    cell.alpha = 1 
    cell.layer.shadowOffset = CGSize(width: 0, height: 0) 
    UIView.commitAnimations() 

} 
+0

Erwägen Sie, Ihrem Code einige Kommentare hinzuzufügen. – HDJEMAI

+0

@Sai Kumar Reddy Vielen Dank. Es funktioniert perfekt – Rex

0

Verwenden Sie diesen Code Animation im Tableview

func tableView(_ tableView: UITableView, willDisplay cell: 
    UITableViewCell, forRowAt indexPath: IndexPath) { 
     let rotationAngleInRadians = 360.0 * CGFloat(M_PI/360.0) 
     let rotationTransform = CATransform3DMakeRotation(rotationAngleInRadians, -500, 100, 0) 
    let rotationTransform = CATransform3DMakeRotation(rotationAngleInRadians, 0, 0, 1) 
     cell.layer.transform = rotationTransform 
     UIView.animate(withDuration: 1.0, animations: {cell.layer.transform = CATransform3DIdentity}) 
} 
4

Swift 4

zu erreichen zu bekommen
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    cell.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) 
    UIView.animate(withDuration: 0.4) { 
     cell.transform = CGAffineTransform.identity 
    } 
} 
+0

muss überschreiben .. – tsukimi

+1

Ehrfürchtig, genau das, was ich brauchte –