#removeFromSuperview
Explore tagged Tumblr posts
Video
youtube
Swift Animations: Awesome Facebook Pop Up! Press and Hold (Ep 1)
my review point is /10
https://youtu.be/wbmTy32s7GQ?t=6m13s remove status bar
https://youtu.be/wbmTy32s7GQ?t=7m20s long press gesture recognizer를 설치
https://youtu.be/wbmTy32s7GQ?t=10m40s stack view를 통해 여러개의 버튼을 담을 콘테이너 만들기
https://youtu.be/wbmTy32s7GQ?t=12m55s 상황에 따라 ui view를 더하거나 제거하는 방법 (removeFromSuperview, addSubview)
https://youtu.be/wbmTy32s7GQ?t=13m41s 터치가 이루어진 위치를 찾고 그 위치에 ui view를 첨가했다가 사라지게 하는 작업
https://youtu.be/wbmTy32s7GQ?t=18m37s 실제 ui view의 애니메이션 제작 작업
#ios#animation#brian#status bar#status#recognizer#gesture#press#long press#stackview#stack#removeFromSuperview#addsubview
0 notes
Text
Volume View iOS Tutorial
When using audio in your app sometimes you want the user to change the volume. With the help of the MPVolumeView object you create a builtin Volume control which also has the abilty to redirect the output to an airplay device. In this tutorial we will play a sound and display the volume controls.This tutorial is made with Xcode 9 and built for iOS 11.
Open Xcode and create a new Single View App.
For product name, use IOS11VolumeViewTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and choose Next.
Some audio is needed to play, so download the music file and add it to the project, make sure "Copy items if needed" is selected
Go to the Storyboard and drag two Buttons to the main view. Set the title of the left button to Play. Select the Button and select the Auto Layout pin button. Pin the Button to the top and left and click "Add 2 Constraints".
Set the title of the right button to Stop. Select the Button and select the Auto Layout pin button. Pin the Button to the top and right and click "Add 2 Constraints".
The Storyboard should look like this.
Select the Assistant Editor and make sure the ViewController.swift is visible. Ctrl and drag from the Play Button to the ViewController class and create the following Action
Ctrl and drag from the Stop Button to the ViewController class and create the following Action
The AVFoundation framework is needed for playing the music file and the MediaPlayer framework to use the MPVolumeView. Go to the ViewController.swift file and import the frameworks
import AVFoundation import MediaPlayer
Inside the ViewController class add the following properties
var audioPlayer = AVAudioPlayer() let wrapperView = UIView(frame: CGRect(x: 30, y: 200, width: 300, height: 20))
Implement the viewDidLoad method
override func viewDidLoad() { super.viewDidLoad() // 1 let path = Bundle.main.path(forResource: "Amorphis - My Enemy", ofType: "mp3") let music = NSURL(fileURLWithPath: path!) as URL // 2 do { try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) try AVAudioSession.sharedInstance().setActive(true) try audioPlayer = AVAudioPlayer(contentsOf: music) audioPlayer.prepareToPlay() } catch { print("error") } }
The audio file is extracted from the Application's bundle
The audio session category is set to playback and set to active.
Implement the playSound method
@IBAction func playSound(_ sender: Any) { // 1 audioPlayer.play() // 2 view.backgroundColor = UIColor.clear view.addSubview(wrapperView) // 3 let volumeView = MPVolumeView(frame: wrapperView.bounds) wrapperView.addSubview(volumeView) }
The audio file starts to play
The wrapper view is added as a subview to the main view
The MPVolumeView is added as a subview of the wrapper view.
Implement the stopSound method.
@IBAction func stopSound(_ sender: Any) { audioPlayer.stop() wrapperView.removeFromSuperview() }
The audio is stopped and the wrapperView including the volume view is removed from the superview.
Build and Run the project, select the play button and change the volume and Output source. Note this can only be run on an actual device, since in the iOS Simulator you will only see a black view.
You can download the source code of the IOS11VolumeViewTutorialat the ioscreator repository on Github.
0 notes
Text
Adding fadeout effect to any -[UIViews removeFromSuperview]
Typically you like to do something like below when you wanted to remove a view from its parent view.
[myView removeFromSuperview];
Sometimes it's not that please for a user to see an UI component disappearing suddenly. You'd then consider adding some transition effects, and here's a little code snippet in the UIView+JTRemoveAnimated category for how you can get a fade out effect on view removal. So from now on, you just needed to do this to fade out any UIViews
[myView removeFromSuperviewAnimated]
25 notes
·
View notes