Skip to content

Commit

Permalink
Merge pull request #12 from Kotivskyi/master
Browse files Browse the repository at this point in the history
adding option to enable APNGImageView animation in scroll view
  • Loading branch information
onevcat committed Feb 23, 2016
2 parents bc43b22 + 375eaff commit 281aef5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion APNGKit/APNGImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public class APNGImageView: UIView {
}
}

// If true runs animation timer with option: NSRunLoopCommonModes
// ScrollView(CollectionView, TableView) items with Animated APNGImageView will not freez during scrolling
// Warning: this may decrease scrolling smoothness with lot's of animations
public var allowAnimationInScrollView = false

var timer: CADisplayLink?
var lastTimestamp: NSTimeInterval = 0
var currentPassedDuration: NSTimeInterval = 0
Expand Down Expand Up @@ -137,7 +142,7 @@ public class APNGImageView: UIView {
timer = CADisplayLink.apng_displayLink({ [weak self] (displayLink) -> () in
self?.tick(displayLink)
})
timer?.addToRunLoop(mainRunLoop, forMode: NSDefaultRunLoopMode)
timer?.addToRunLoop(mainRunLoop, forMode: (self.allowAnimationInScrollView ? NSRunLoopCommonModes : NSDefaultRunLoopMode))
}

/**
Expand Down
6 changes: 3 additions & 3 deletions APNGKitDemo/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8187.4" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8151.3"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -23,7 +24,6 @@
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" red="0.26666666666666666" green="0.29019607843137252" blue="0.34901960784313724" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="oMc-vi-mZv" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="05h-T1-Ckg"/>
Expand Down

0 comments on commit 281aef5

Please sign in to comment.