如果你在iOS9.0中还使用UIAlertView的话,那么XCode一定会告诉你你使用的已经过时了,请使用全新的UIAlertController,用它来实现新的提示。那么具体怎么玩呢?我刚好写了一个简单的例子。看源码:
顺带了一个手势的
// // ViewController.swift // SwipeGensture // // Created by leehom on 16/2/1. // Copyright © 2016年 lee.demo. All rights reserved. // import UIKit class ViewController: UIViewController { @IBOutlet var view01: UIView! @IBOutlet var testButton: UIButton! var offsetX: CGFloat = 0 var offsetY: CGFloat = 0 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let gestureLeft = UISwipeGestureRecognizer(target: self, action: "handSwipe:") gestureLeft.direction = UISwipeGestureRecognizerDirection.Left view01.addGestureRecognizer(gestureLeft) let gestureRight = UISwipeGestureRecognizer(target: self,action: "handSwipe:") gestureRight.direction = UISwipeGestureRecognizerDirection.Right view01.addGestureRecognizer(gestureRight) let gestureUp = UISwipeGestureRecognizer(target: self, action: "handSwipe:") gestureUp.direction = UISwipeGestureRecognizerDirection.Up view01.addGestureRecognizer(gestureUp) let gestureDown = UISwipeGestureRecognizer(target: self, action: "handSwipe:") gestureDown.direction = UISwipeGestureRecognizerDirection.Down view01.addGestureRecognizer(gestureDown) } func handSwipe(gesture:UISwipeGestureRecognizer){ let dir = gesture.direction switch(dir){ case UISwipeGestureRecognizerDirection.Left: offsetX -= 20 break; case UISwipeGestureRecognizerDirection.Right: offsetX += 20 break; case UISwipeGestureRecognizerDirection.Up: offsetY -= 20 break; case UISwipeGestureRecognizerDirection.Down: offsetY += 20 break; default: break; } view01.transform = CGAffineTransformMakeTranslation(offsetX,offsetY) let x = view01.frame.origin.x let y = view01.frame.origin.y NSLog("%2f,%2f", x,y) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func btnTestClick(sender: UIButton) { if (sender == testButton){ let alert = UIAlertController(title: "提示", message: "你要退出吗?", preferredStyle: UIAlertControllerStyle.Alert) let okAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default, handler: { (UIAlertAction) -> Void in NSLog("YES") }) let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: { (UIAlertAction) -> Void in NSLog("NO") }) alert.addAction(okAction) alert.addAction(cancelAction) self.presentViewController(alert, animated: true, completion: { () -> Void in NSLog("Done") }) }else{ NSLog("No") } } }
顺带了一个手势的
收藏的用户(0) X
正在加载信息~
推荐阅读
最新回复 (0)
站点信息
- 文章2313
- 用户1336
- 访客11715360
每日一句
Learning never exhausts the mind.
学习永远不会使头脑疲惫。
学习永远不会使头脑疲惫。
php慎用foreach引用&
Vue+ElementUI简单教程(vue-element-admin)
ThinkPad E431 安装黑苹果
程序员必看的最佳科技电影
How to Ungroup Icons on Windows 11 Taskbar With a Registry Hack (and 2 More Ways)
如何在iPhone上移动多个应用程序
文本转语音系统Spark-TTS
Netty基本使用介绍
微信小程序F2图表——Cannot read property 'source' of null
2020机器学习的5大编程语言
8位数QQ官方注册过滤法
反编译修改class文件变量
Notepad++如何代码格式化——NppAStyle
新会员