프로그래밍/IOS

[IOS] 로딩 스피너 & 알림창 : Spinner & Alert

Gilvert 2016. 1. 1. 14:55
728x90

#1. 목표

- 로딩시 돌아가는 애니매이션 연출 및 알림 팝업창 만들기


#2. 정리

1. 스피너: 로딩시 돌아가는 애니매이션 만들기

1) UIActivityIndicatiorView 객체 생성

2) 사이즈 설정

3) 화면 정중앙 설정

4) 멈추면 감추게 해주세요?

5) Gray 스타일 적용

6) View 화면에 더하기

7) 애니매이션 적용

8) 인터렉션 이벤트를 무시하기

* 소스

    var activityIndicator : UIActivityIndicatorView = UIActivityIndicatorView()

   @IBAction func pause(sender: AnyObject) {

        activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))

        activityIndicator.center = self.view.center

        activityIndicator.hidesWhenStopped = true

        activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray

        view.addSubview(activityIndicator)

        activityIndicator.startAnimating()

       // UIApplication.sharedApplication().beginIgnoringInteractionEvents()

    }

9) 스피너 멈추기

    @IBAction func restore(sender: AnyObject) {

        activityIndicator.stopAnimating()

    }


2. 알림참 띄우기

1) UIAlertController 부터는 IOS 버전 특성을 타게됨

2) 타이틀, 메시지 설정

3) ok 버튼 삽입: 화면창 닫힘

4) 화면창에 적용


    @IBAction func createAlert(sender: AnyObject) {

        if #available(iOS 8.0, *) {

            var alert = UIAlertController(title: "Hey there", message: "Are you sure?", preferredStyle: UIAlertControllerStyle.Alert)

            alert.addAction(UIAlertAction(title: "ok", style: .Default, handler: { (action) -> Void in

                self.dismissViewControllerAnimated(true, completion: nil )

            }))

            self.presentViewController(alert, animated: true , completion: nil )

        } else {

            // Fallback on earlier versions

        }

    }


가우넷 구름 USB 충전식 양면 대용량 보조배터리 손난로, 단일 상품, 화이트



"파트너스 활동을 통해 일정액의 수수료를 제공받을 수 있음"