У меня есть представление, которое содержит scrollview и uiwebview с html внутри него. Я пытаюсь, чтобы scrollview медленно автоматически прокручивался вниз, останавливался при касании, а затем перезапускал анимацию в текущей позиции.Имейте UIScrollView Animation Пауза и перезагрузка на жесте Touch
На данный момент у меня есть html-показ, прокрутка прокрутки и касание, останавливающее прокрутку, но я не могу заставить анимацию прокрутки снова запускаться в текущей позиции через определенное количество времени после касания , Вот код:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myHTML = @"<html><body><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1><h1>Hello, world!</h1></body></html>";
[self.webView loadHTMLString:myHTML baseURL:nil];
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userDidTapWebView)];
[self.webView addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];
//Start the scrolling
[self startAnimation];
}
#pragma mark - Gesture Delegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch {
//Stop the scrollview from scrolling when the screen is touched
[self.scrollView.layer removeAllAnimations];
return YES;
}
#pragma mark - Animate Methods
-(void)startAnimation{
[UIScrollView beginAnimations:@"scrollAnimation" context:nil];
[UIScrollView setAnimationDuration:8.0f];
[self.scrollView setContentOffset:CGPointMake(0 , 100)];
[UIScrollView commitAnimations];
}
-(void)dealloc{
[super dealloc];
[self.webView release];
[self.scrollView release];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Я реализовал код, и методы делегата все еще не подхватили. – user1079052
Какие методы делегата? –