ios


swift stop 360 degree animation


in my swift 2 app, i have this extension:
extension UIView {
func rotate360Degrees(duration: CFTimeInterval = 2.5, completionDelegate: AnyObject? = nil) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(M_PI * 2.0)
rotateAnimation.duration = duration
if let delegate: AnyObject = completionDelegate {
rotateAnimation.delegate = delegate
}
self.layer.addAnimation(rotateAnimation, forKey: nil)
}
}
with this code, i can rotate an image 360 degree.
now i would like to stop this animation directly after i pressed on a button.
in my view controller is an action for my button. if i press this button, the following value will set:
self.shouldStopRotating = true
and i have this code part in the same vc, too:
override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if self.shouldStopRotating == false {
self.LoadingCircle.rotate360Degrees(completionDelegate: self)
}
}
the image will stop after i pressed the button, but it will stop after the animation will be finished (after 360 degrees) - but this is to late.
the image have to stop rotating directly on the actual position after i press the button
Try to add this when the button that stops the animation is presse:
self.LoadingCircle.layer.removeAllAnimations()
let currentLayer = self.LoadingCircle.layer.presentationLayer();
let currentRotation = currentLayer?.valueForKeyPath("transform.rotation.z")?.floatValue;
let rotation = CGAffineTransformMakeRotation(CGFloat(currentRotation!));
self.LoadingCircle.transform = rotation;

Related Links

How to add number of rows in section dynamically in tableview? [closed]
iOS Network Connection Failure Policy suggestions
TTTAttributedLabel link font changing when UIAlertView presents
tell an array to hold instances of an array?
Add Vibrancy effect to custom UIButton?
Image buffer display order with VTDecompressionSession
What is that? Cell or Table? [closed]
Setting up proxy server on iPhone
iOS/FBSDK - FBSDKProfile is nil on device, works fine on simulator
NSMutableAttributedString check nil value [duplicate]
How to use cocoapods with playground?
iOS: Switch UIViews using ReactiveCocoa
AFNetworking HTTP POST Success Empty
exc_bad_access on touch UITextField
Deleting items in Core Data
iOS: Find language of current location

Categories

HOME
amazon-s3
graph
oozie
jsp
collections
dicom
azure-search
android-sqlite
isis
google-cloud-dataproc
restsharp
microsoft-dynamics
drag
windows-10-desktop
uwsgi
nanotime
python-2.5
export-to-excel
installer
amadeus
records
man
nested-set-model
weather-api
spring-batch-admin
number-formatting
x-sendfile
graphql-dotnet
coqide
codeceptjs
concurrenthashmap
charts.js
breakpoint-sass
scom
dokuwiki
complex-networks
aem-6
api-doc
transpose
runc
essbase
hawkular
adsutil.vbs
docker-swarm-mode
derbyjs
ammonite
webloadui
untagged
nuget-package-restore
kie-workbench
android-alertdialog
logstash-jdbc
android-chips
measurement-protocol
building
rsh
webclient-download
nuitka
groups
js-of-ocaml
occam-pi
subroutine
php-opencloud
sqlj
radix-sort
android-print-framework
antiforgerytoken
cvs2git
razor-2
catalina.out
dotliquid
qt4.7
freemind
ccombobox
nspersistentdocument
wescheme
rc-shell
onmouseout
arr
ms-access-97
junitperf
measure
remote-control
n900
custom-protocol
network-scan
time-estimation
eclipse-tptp
resharper-4.5
shareware
graceful-degradation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App