- (void)viewDidLoad
{
[super viewDidLoad];
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:4.0f
target:self
selector:@selector(create)
userInfo:bounce
repeats:YES];
}
//здесь я двигаю объект bounce в зависимости от нажатий.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
PUSH=YES;
UITouch *Touch = [[event allTouches]anyObject];
CGPoint location = [Touch locationInView:Touch.view];
if ( (location.x <160)&&(location.y>=496)) {
[UIView setAnimationDuration:0.1f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
if (bounce.center.x>20) {bounce.center = CGPointMake(bounce.center.x - 20 , bounce.center.y); }
}
if ((location.x > 160)&&(location.y>=496)) {
[UIView setAnimationDuration:0.1f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
if (bounce.center.x<300) {bounce.center = CGPointMake(bounce.center.x + 20 , bounce.center.y); }
}
}
//тут я создаю некоторую стену и двигаю ее вниз
-(void)create {
CGRect lab = CGRectMake(0, 0, 70, 50);
l = [[UIImageView alloc] initWithFrame:lab];
l.backgroundColor=[UIColor greenColor];
[self.view addSubview:l];
NSLog(@"%f %f",l.center.x, l.center.y);
[_labels addObject:l];
CGRect lab1 = CGRectMake(110, 0, 320, 50);
l1 = [[UIImageView alloc] initWithFrame:lab1];
l1.backgroundColor=[UIColor greenColor];
[self.view addSubview:l1];
NSLog(@"%f %f",l1.center.x, l1.center.y);
[_labels addObject:l1];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
//[UIView setAnimationDidStopSelector:@selector(animationfinished:finished:context:)];
//[UIView setAnimationDelegate:self];
l.center = CGPointMake(35 , 600);
l1.center = CGPointMake(270, 600);
}