UIScrollView прокручивается вниз при загрузке. Не прокручивается после - PullRequest
1 голос
/ 29 февраля 2012

В моем приложении у меня есть mainView. В этом mainView у меня есть еще один UIView с именем sideNav и UIScrollView с именем scrollView. В UIScrollView у меня есть еще один вид под названием rulesView. Проблема, с которой я столкнулся, заключается в следующем: scrollView прокручивается до самого конца представления и не перемещается после. У меня есть два жеста смахивания на вид (см. Код ниже), которые работают. В прошлый раз у меня возникла эта проблема, потому что я дважды устанавливал contentSize UIScrollView. Я устанавливаю это только один раз здесь. Если у кого-то есть идеи, что может быть не так, я был бы очень признателен. Заранее спасибо.

#import "MemberRulesViewController.h"

@implementation MemberRulesViewController

@synthesize btnVisitWeb, webView, scrollView, rulesView, btnSideHome, btnSideBrowse, btnSideFave, btnSideNew, btnSideCall, btnSideBeset, btnSideEmail, btnSideCancelled, menuOpen, navBarTitle, mainSearchBar, tap, sideNav, mainView;

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.font = [UIFont fontWithName:@"STHeitiSC-Medium" size:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:1.0];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = @"Browse";
self.navBarTitle.titleView = label;
[label sizeToFit];

tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
tap.delegate = self;
tap.cancelsTouchesInView = NO;

UISwipeGestureRecognizer *oneFingerSwipeLeft = 
[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)];
[oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:oneFingerSwipeLeft];

UISwipeGestureRecognizer *oneFingerSwipeRight = 
[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
[oneFingerSwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[[self view] addGestureRecognizer:oneFingerSwipeRight];

menuOpen = NO;


scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.scrollsToTop = YES;
scrollView.contentSize = CGSizeMake(320, 3638);
rulesView.frame = CGRectMake(0, 0, 320, 3638);
mainView.frame = CGRectMake(0, 0, 320, 3638);

[super viewDidLoad];
}

-(IBAction)vistWeb:(id)sender{

webView = [[WebViewController alloc]
           initWithNibName:@"WebView" bundle:[NSBundle mainBundle]];
webView.url=@"http://www.passport-america.com";
[self.navigationController pushViewController:webView animated:YES];

}

-(IBAction)goBack:(id)sender{

[self.navigationController popViewControllerAnimated:YES];

}

-(void) dismissKeyboard {

[mainSearchBar resignFirstResponder];

}

-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([animationID isEqualToString:@"slideMenu"]){
    UIView *sq = (__bridge UIView *) context;
    [sq removeFromSuperview];

}
}

- (IBAction)menuTapped {
NSLog(@"Menu tapped");
//CGRect frame = self.detailsView.frame;
CGRect scrollFrame = self.scrollView.frame;
//CGRect imageFrame = self.imageView.frame;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector( animationDidStop:finished:context: )];
//[UIView beginAnimations:@"slideMenu" context:(__bridge void *)(self.detailsView)];
[UIView beginAnimations:@"slideMenu" context:(__bridge void *)(self.scrollView)];

if(!menuOpen) {
    //frame.origin.x = 212;
    scrollFrame.origin.x = -212;
    //imageFrame.origin.x = -212;
    menuOpen = YES;
    sideNav.hidden = NO;
}
else
{
    //frame.origin.x = 0;
    scrollFrame.origin.x = 0;
    //imageFrame.origin.x = 0;
    menuOpen = NO;
    sideNav.hidden = YES;
}

//self.detailsView.frame = frame;
self.scrollView.frame = scrollFrame;
//self.imageView.frame = imageFrame;
[UIView commitAnimations];
}

-(IBAction) sideHome:(id)sender{

CGRect frame = self.scrollView.frame;
frame.origin.x = 0;
self.scrollView.frame = frame;
menuOpen = NO;
sideNav.hidden = YES;
PassportAmericaViewController *homeView = [[PassportAmericaViewController alloc]
                                           initWithNibName:@"PassportAmericaViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:homeView animated:YES];

}
-(IBAction) sideBrowse:(id)sender{

CGRect frame = self.scrollView.frame;
frame.origin.x = 0;
self.scrollView.frame = frame;
menuOpen = NO;
sideNav.hidden = YES;
BrowseViewController *browseView = [[BrowseViewController alloc]
                                    initWithNibName:@"BrowseView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:browseView animated:YES];

}
-(IBAction) sideBeset:(id)sender{

CGRect frame = self.scrollView.frame;
frame.origin.x = 0;
self.scrollView.frame = frame;
menuOpen = NO;
sideNav.hidden = YES;
BesetCampgroundMapViewController *besetMapView = [[BesetCampgroundMapViewController alloc]
                                                  initWithNibName:@"BesetCampgroundMapView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:besetMapView animated:YES];

}
-(IBAction) sideFave:(id)sender{

CGRect frame = self.scrollView.frame;
frame.origin.x = 0;
self.scrollView.frame = frame;
menuOpen = NO;
sideNav.hidden = YES;
FavoritesViewController *faveView = [[FavoritesViewController alloc] initWithNibName:@"FavoritesView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:faveView animated:YES];

}
-(IBAction) sideNew:(id)sender{

CGRect frame = self.scrollView.frame;
frame.origin.x = 0;
self.scrollView.frame = frame;
menuOpen = NO;
sideNav.hidden = YES;
NewCampgroundsViewController *theNewCampView = [[NewCampgroundsViewController alloc]
                                                initWithNibName:@"NewCampgroundsView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:theNewCampView animated:YES];

}
-(IBAction) sideCancelled:(id)sender{

CGRect frame = self.scrollView.frame;
frame.origin.x = 0;
self.scrollView.frame = frame;
menuOpen = NO;
sideNav.hidden = YES;
CancelledCampgroundsViewController *cancCampView = [[CancelledCampgroundsViewController alloc]
                                                    initWithNibName:@"CancelledCampgroundsView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:cancCampView animated:YES];

}
-(IBAction) sideCall:(id)sender{

NSLog(@"Calling Passport America...");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:8002837183"]];

}
-(IBAction) sideEmail:(id)sender{

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"mailto:info@passport-america.com"]];

}

-(void) searchBarSearchButtonClicked: (UISearchBar *)searchBar {
SearchViewController *search = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:[NSBundle mainBundle]];
NSString *searchText = [[NSString alloc] initWithString:mainSearchBar.text];
search.searchText = searchText;
[self.navigationController pushViewController:search animated:YES];
}

-(void) swipeLeft:(UISwipeGestureRecognizer *)recognizer {
if (!menuOpen) {
    CGRect frame = self.scrollView.frame;
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector( animationDidStop:finished:context: )];
    [UIView beginAnimations:@"slideMenu" context:(__bridge void *)(self.scrollView)];
    frame.origin.x = -212;
    menuOpen = YES;
    self.scrollView.frame = frame;
    //table.userInteractionEnabled = NO;
    [UIView commitAnimations];

} else {
    //menu already open, do nothing
}
}

-(void) swipeRight:(UISwipeGestureRecognizer *)recognizer {
if (!menuOpen) {
    //menu closed, do nothing
} else {
    CGRect frame = self.scrollView.frame;
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector( animationDidStop:finished:context: )];
    [UIView beginAnimations:@"slideMenu" context:(__bridge void *)(self.scrollView)];
    frame.origin.x = 0;
    menuOpen = NO;
    self.scrollView.frame = frame;
    //table.userInteractionEnabled = YES;
    [UIView commitAnimations];

}
}


- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...