如果你在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
- 访客11482433
每日一句
Judge not from appearances.
人不可貌相,海不可斗量。
人不可貌相,海不可斗量。
区块链,人工智能和物联网如何彻底改变企业
Vue异常Uncaught (in promise)解决方法
IDEA创建SpringBoot项目详细步骤
微信小程序,一个有局限的类似 React Native 轮子!
华为手机app闪退重启界面清空log日志问题
JavaScript | Blob类型
【续】cocos2d-x横版ARPG过关游戏
UAC的限制引起WM_DROPFILES无法响应的解决办法
【软件多开】多用户远程桌面-RDPWrap
Galaxy X:三星的可折叠手机必须向中兴通讯学习
Android Studio使用Opencv2.4.9进行NDK开发
CentOS 搭建 OpenVPN 服务
Mac os Android Studio 快捷键冲突解决方案
新会员