UIScrollView在加载时滚动到底部。之后不可滚动

时间:2012-02-28 21:20:56

标签: iphone objective-c uiscrollview

在我的应用中,我有mainView。在这个mainView中,我有另一个名为sideNav的UIView和一个名为scrollView的UIScrollView。在UIScrollView中,我还有另一个名为rulesView的视图。我遇到的问题是:scrollView一直滚动到视图的底部,之后不会移动。我在视图上有两个滑动手势(见下面的代码)。我最后一次遇到这个问题,是因为我正在设置两次UIScrollView的contentSize。我只在这里设置一次。如果有人有任何想法可能是错的,我会非常感谢输入。提前谢谢。

#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

0 个答案:

没有答案
相关问题