@interface ViewController ()
@property UIView *renview;
@end
@implementation ViewController
- (void)viewDidLoad
{
UIView *renview=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
renview.backgroundColor=[UIColor blackColor];
[self.view addSubview:renview];
self.renview=renview;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[touches anyObject];
CGPoint location=[touch locationInView:self.view];
CGPoint plocation=[touch previousLocationInView:self.view];
CGPoint deltapLocation=CGPointMake(location.x-plocation.x, location.y-plocation.y);
CGPoint newcenter=CGPointMake(self.renview.center.x+deltapLocation.x, self.renview.center.y+deltapLocation.y);
[self.renview setCenter:newcenter];
}