A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

2黑马币
@interface ViewController ()
@property (nonatomic,weak) UIView *rightView;
@property (nonatomic,weak) UIView *leftView;
@property (nonatomic,weak) UIView *mainView;

@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIView *rightView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    rightView.backgroundColor = [UIColor greenColor];
    _leftView = rightView;

    UIView *leftView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    leftView.backgroundColor = [UIColor blueColor];
    _leftView=leftView;

    UIView *mainView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    mainView.backgroundColor = [UIColor redColor];
    _mainView = mainView;
    [self.view addSubview:rightView];
    [self.view addSubview:leftView];
    [self.view addSubview:mainView];

}


-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch =[touches anyObject];
    CGPoint current = [touch locationInView:self.view];
    CGPoint previous = [touch previousLocationInView:self.view];
    CGFloat offX = current.x - previous.x;
        if (_mainView.frame.origin.x>0) {
            _leftView.hidden = NO;
            CGRect frame = _mainView.frame;
            frame.origin.x +=offX;
            frame.origin.y +=offX*0.2;
            frame.size.height -=offX*0.4;
            _mainView.frame = frame;
        }else if(_mainView.frame.origin.x<=0){
            _leftView.hidden = YES;
            CGRect frame = _mainView.frame;
            frame.origin.x +=offX;
            frame.origin.y +=(-offX)*0.2;
            frame.size.height -=(-offX)*0.4;
            _mainView.frame = frame;
        }

}
@end

该程序运行是会有Bug的,,求高人指点一二,算法上没有问题,个人感觉比

    左右滑动都正常   多次左右滑动后


3 个回复

倒序浏览
还在学习中,楼主也要好好努力学习
回复 使用道具 举报
努力学习中
回复 使用道具 举报
。。。争取尽快能看懂
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马