Skip to content

Commit

Permalink
Improving drawing performnace
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenyneu committed Sep 21, 2015
1 parent d973ebc commit 7173558
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Cosmos/CosmosView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,24 @@ Shows: ★★★★☆ (132)
super.init(frame: frame)
update()
self.frame.size = intrinsicContentSize()

improvePerformance()
}

/// Initializes and returns a newly allocated cosmos view object.
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

improvePerformance()
}

/// Change view settings for faster drawing
private func improvePerformance() {
/// Cache the view into a bitmap instead of redrawing the stars each time
layer.shouldRasterize = true
layer.rasterizationScale = UIScreen.mainScreen().scale

opaque = true
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Cosmos/StarLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct StarLayer {
layer.bounds.size = CGSize(width: size, height: size)
layer.masksToBounds = true
layer.path = path
layer.opaque = true
return layer
}

Expand All @@ -80,6 +81,7 @@ struct StarLayer {
layer.anchorPoint = CGPoint()
layer.masksToBounds = true
layer.bounds.size = CGSize(width: size, height: size)
layer.opaque = true
return layer
}

Expand Down
15 changes: 15 additions & 0 deletions Distrib/CosmosDistrib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,24 @@ Shows: ★★★★☆ (132)
super.init(frame: frame)
update()
self.frame.size = intrinsicContentSize()

improvePerformance()
}

/// Initializes and returns a newly allocated cosmos view object.
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

improvePerformance()
}

/// Change view settings for faster drawing
private func improvePerformance() {
/// Cache the view into a bitmap instead of redrawing the stars each time
layer.shouldRasterize = true
layer.rasterizationScale = UIScreen.mainScreen().scale

opaque = true
}

/**
Expand Down Expand Up @@ -1272,6 +1285,7 @@ struct StarLayer {
layer.bounds.size = CGSize(width: size, height: size)
layer.masksToBounds = true
layer.path = path
layer.opaque = true
return layer
}

Expand All @@ -1288,6 +1302,7 @@ struct StarLayer {
layer.anchorPoint = CGPoint()
layer.masksToBounds = true
layer.bounds.size = CGSize(width: size, height: size)
layer.opaque = true
return layer
}

Expand Down

0 comments on commit 7173558

Please sign in to comment.