如果你在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
- 访客11285841
每日一句
Whatever the mind can conceive and believe, it can achieve.
心智能想到并相信的,就能实现。
心智能想到并相信的,就能实现。
【教程】win10 彻底卸载edge浏览器
Google Play商城将85款恶意App下架
Android模拟屏幕点击的基本原理
Android Studio创建进程通信简单例子
MPAndroidChart曲线非连续改装笔记
快来学习Google出品的序列化神器Protocol Buffer
P2P中NAT之间的打洞可能性
Android Studio 提示Session 'app':Error Installing APK
区块链,人工智能和物联网如何彻底改变企业
wampserver安装:因为计算机中丢失MSVCR110.dll
打开显示interface.png 或者显示interface.swf
Android Studio使用DB Browser查看SQLite数据库
新安装centos不能上网的问题解决方法
新会员