UI13小球拖拽

//

//  BallView.m

//  UI13小球拖拽

//

//  Created by focus on 2017/1/22.

//  Copyright © 2017年 focus. All rights reserved.

//

 

#import "BallView.h"

 

@implementation BallView

 

- (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    //在这方法里获取起点

    //获取触摸对象  NSSet<UITouch是C++聚合方法

    UITouch * touch = [touches anyObject];

    //找到点击的点

    self.startPoint = [touch locationInView:self];

    

    

}

 

- (void) touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    //在这方法让小球动起来

    //先获取触摸对象

    UITouch * touch = [touches anyObject];

    //获取移动中的点

    CGPoint newPoint = [touch locationInView:self];

    //计算X Y坐标分别移动多少

    CGFloat dx = newPoint.x - self.startPoint.x;

    CGFloat dy = newPoint.y - self.startPoint.y;

    

    // 改变小球的位置

    self.center =CGPointMake(self.center.x+dx, self.center.y+dy);

}

 

- (void) touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    //

}

 

 

 

 

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/

 

@end

 

转载于:https://my.oschina.net/VincentOSC/blog/829333

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
程序主要有两个部分组成,一个程序的显示部分,一个程序的设置部分,显示部分主要是一个可以用手指拖动圆形小球,设置部分主要是对小球的颜色和大小进行参数设置。 1.1 View-ViewController 主要有三个ViewController,一个是用于显示的MainViewController,还有一个是用于设置的SetingsViewController,还有一个是用于设置小球颜色ColorSettingViewController. 一个RoundBallView,进行显示小球的View。 程序第一次开启的时候,小球的坐标是界面上一个(30,30)这个位置,小球颜色为红色,直径为50像素。SettingsView的Color选项为Red,Size为最小值50。ColorSettingView的CheckMark为Red。 MainView主要对小球进行拖动操作,程序重启后,小球的位置是最后一次拖动的坐标。 SetingsViewController的第一表格引导进入ColorSettingView,SetingsViewController的第二表格设置小球大小的变化,MainView始终保持小球最后一次设置的大小,小球的直径的最大值为100,最小值为50。 在ColorSettingViewController进行颜色参数的改变后能直接引起MainViewController中小球颜色对应变化,还有SetingsView的当前颜色的文字描述的对应变化,还有ColorSettingView自身的CheckMark的所在行。 程序开启的时候始终保持上次最终的状态。 MainView进入SetingView为垂直进入,SetingView进入ColorSettingView为导航横向进入。 1.2 Controller MainViewController,SetingViewController ,ColorSettingViewController三个都是简单ViewController,MainViewController,SetingViewController可以直接继承UIViewController, ColorSettingViewController继承UITableViewController
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值