Difference between revisions of "Swift code snippets"

From Hawk Wiki
Jump to: navigation, search
m (Swift: Convert between CGImage, CIImage and UIImage)
(Swift Detect Volumn Button Press)
Line 26: Line 26:
 
==[[Swift: Convert between CGImage, CIImage and UIImage]]==
 
==[[Swift: Convert between CGImage, CIImage and UIImage]]==
  
==Swift Detect Volumn Button Press==
+
==[[Swift:Detect Volumn Button Press]]==
Credit to http://stackoverflow.com/questions/28471481/swift-detect-volume-button-press
+
 
+
Detect volume button press, also hide volume HUD
+
 
+
<pre class="brush:swift">
+
import MediaPlayer //Only for hidding  Volume view
+
func listenVolumeButton(){
+
 
+
    let audioSession = AVAudioSession.sharedInstance()
+
    audioSession.setActive(true, error: nil)
+
    audioSession.addObserver(self, forKeyPath: "outputVolume", options: NSKeyValueObservingOptions.New, context: nil)
+
    //If you want to hide Volume HUD view
+
    var volumeView: MPVolumeView = MPVolumeView(frame: CGRectZero)
+
    view.addSubview(volumeView)
+
}
+
 
+
override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject,
+
    change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
+
    if keyPath == "outputVolume"{
+
        print("got in here")
+
    }
+
}
+
 
+
</pre>
+

Revision as of 04:16, 23 March 2015

Swift Code snippts

Back To IOS_Swift

Swift: Use NSUserDefaults to Store Persistence Data

Swift: Making Network Request Using NSURLConnection

Swift:Use AFNetworking setImageWithURL

Swift:Using UIRefreshControl

Swift:Example of fetching messages from Parse

https://gist.github.com/sandofsky/7134b1ff90d235901254

Swift:Auto Table Row Height

Swift:Navigation between storyboards

Swift:Notification Observer Using NSNotificationCenter

Swift:Get Raw Histogram from CGImage

Swift:UIGraphics Drawing on UIView

Swift:UIGraphics Scale Down CGImage

Swift: Convert between CGImage, CIImage and UIImage

Swift:Detect Volumn Button Press