多语言展示
当前在线:1996今日阅读:27今日分享:41

iOS开发 制作iPhone白点

用过iPhone手机的伙伴都知道,iPhone手机屏幕上有一个小白点。用户可以点击白点,选择里面列出来的功能可以快速实现某操作,提升用户体验满意度。毕竟苹果手机可是说,一台手机只需要一个按键就可以了。对于白点,用处大,也好玩。我们可以在自己的APP上制作一个白点,一点击就跳转到主页或者启动分享功能,也可以随处滑动,飘来飘去,非常漂亮。
工具/原料
1

MAC OS X操作系统

2

Xcode编译器

方法/步骤
1

创建工程项目和视图控制器      创建工程项目WhiteSpots白点,新建一个UIViewController。选中工程,右键-New File…选择“Cocoa Touch Class”-Next,给个合理的名称ViewController,再宿沫久Next完成。      在AppDelegate.m文件包含#import 'ViewController.h'。添加代码:self.window.rootViewController = [[ViewController alloc]init];将ViewController设置为根视图控制器。      为了美观,设置View的背景颜色为紫色。self.view.backgroundColor = [UIColor purpleColor];      现在执行编译,run一下,效果如图。

2

添加白点及点击响应事件      选择UIButton、UIView、UIImageView作为白点都是可以的。当前使用UIButton,因为UIButton具有UIControl的属性,自带点击事件,也有背景图片。代召段码如下:    UIButton *whiteSpotsButton = [UIButton buttonWithType:UIButtonTypeCustom];    whiteSpotsButton.frame = CGRectMake(10, 100, 44, 44);    whiteSpotsButton.backgroundColor = [UIColor whiteColor];    whiteSpotsButton.layer.cornerRadius = 22;    [whiteSpotsButton setTitle:@'白点' forState:UIControlStateNormal];    [whiteSpotsButton setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];    [whiteSpotsButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:whiteSpotsButton];#pragma mark- 按钮点击- (void)btnClick:(UIButton *)sender{    NSLog(@'白点被点击');}编译运行效果如图。

3

添加监听白点的手势      添加手势识别代理UIGestureRecognizerDelegate,创建UIPanGestureRecognizer拖动手势及其响应事件。代码如下:    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanFrom:)];    [self.view bringSubviewToFront:whiteSpotsButton];//放到最前面    [whiteSpotsButton addGestureRecognizer:panRecognizer];//关键语句,添加一个手势监测;    panRecognizer.maximumNumberOfTouches = 1;    panRecognizer.delegate = self;-(void)handlePanFrom:(UIPanGestureRecognizer*)recognizer{    NSLog(@'拖动操作');}

5

代码下载地址:https://github.com/cjq002/WhiteSpots.git  去点击“Download ZIP”下载。

注意事项
1

当前使用MAC OS X 版本为10.9.5

2

当前使用Xcode版本为6.0

推荐信息