如果你在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)
站点信息
- 文章2305
- 用户1336
- 访客11380514
每日一句
Great people do things before they are ready.
伟大的人在准备好前就行动。
伟大的人在准备好前就行动。
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is
Android 8.0应用图标适配
解决vue动态生成el-table-column按钮点击事件
VC++实现远程控制
傻瓜式安装黑苹果的方式,超简单,吐血推荐!
Android最简单方式实现DatePickerDialog只显示年、月、日
mysql查询表索引的命令使用小记
Mac OS解决开机黑屏时间长(秒启动)
使用HTML和CSS设计磨砂玻璃效果
简单利用Clover四叶草安装U盘安装黑苹果
font-awesome-to-png快速将Font-Awesome字体保存为PNG图片
2017年10月编程语言排行榜
XPosed插件自动生成支付宝收款二维码
新会员