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

ABNewPersonViewController does not dismiss the keyboard
Is it useful to create two concurrent queues in IOS?
How to pre-fill email account in google-oauth2 for iOS API
Twitter search api text field value is truncated
How to install root certificate inside iOS app, so it will be trusted when open URL from UIWebView?
JSon and Ambiguos use of subscript
get remote push notification message in background in iOS
Why can't I bold just part of a string in Swift with NSMutableString?
Swift - WebView doesn't detect swipes when loading
Interstitial DFP ad doesn't fill the screen
Q:UITableView scrollview delegate method did not pass the special code
ios Xcode storyboard compact not working
iOS - Where is object stored in application NSUserDefault? [duplicate]
UIImage to NSData fatal error: unexpectedly found nil while unwrapping an Optional value
How to load images for UITableView or UICollectionView from cache everytime
iOS - UITableview cells with shared surface

Categories

HOME
performance
mongodb
asp.net-identity
actions-on-google
magento
hortonworks-data-platform
react-navigation
typeahead.js
stack
feed
microsoft-dynamics
superfish
wavelet
obiee
sparkpost
records
round-robin
ssrs-2008
multiprocessing
similarity
naturallyspeaking
flatbuffers
opensuse
svn2git
json-c
mobile-center
toastr
breakpoint-sass
compass-lucene
pac
subscription
php-5.5
zfs
program-slicing
pulseaudio
openwebanalytics
ms-jet-ace
azure-cdn
ternary
attributerouting
hipi
tryton
autogen
facebook-canvas
graph-traversal
lapply
android-sdk-tools
agile-processes
angular2-rc5
git-config
xmllint
webmail
rabbitvcs
jquery-load
skrollr
radix-sort
thinktecture-ident-server
readline
dbfit
python-dragonfly
wchar-t
ironmq
cng
quasar
json4s
spymemcached
mtp
cocoon-gem
appv
gulp-rename
chunk-templates
cvc4
pegkit
stringr
crowdflower
smarty2
min3d
modern-ui
imake
jasmin
gnat
keyboard-navigation
sirtrevor
yourls
jxta
ramdisk
inputview
freemind
libtorrent-rasterbar
angularjs-module
slimbox
cassette
datakey
tipsy
j#
android-assets
demoscene
xmltextwriter
openfeint
formsauthentication
codi
rails-3.1
wiki-markup
ryz
network-scan
sloc
gedcom
crc-cards
plumtree

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