@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的,,求高人指点一二,算法上没有问题,个人感觉比
|