重新进入视图时,UIScrollView不会滚动

时间:2012-11-30 00:13:54

标签: iphone uiscrollview ios6

我有UIView(当然在视图控制器中),在UIView内,我有一个UIScrollViewUIScrollView包含一些图像和按钮。其中一个按钮使用模态动作Segue并在UIView内部打开MapView,然后打开"返回"底部的按钮会将您带回上一个UIView。但是一路走来"回来" (从MapViewUIView),UIScrollView 不再滚动,就像在转到MapView之前一样。它就像锁定在它的最高位置一样。我觉得这与代表有什么关系?不过我不知道,我还不太清楚。无论如何,我对滚动问题的任何见解?谢谢!

这是我的.h文件(我的滚动视图在哪里):

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface ThirdViewController : UIViewController <UIScrollViewDelegate, UIScrollViewAccessibilityDelegate>

@property (strong, nonatomic) IBOutlet UIView *findUsView;
@property (weak, nonatomic) IBOutlet UIScrollView *findUsScrollView;
- (IBAction)callButton:(id)sender;
- (IBAction)getDirButton:(id)sender;

@end

这是我的.m文件(我的滚动视图在哪里):

#import "ThirdViewController.h"

@implementation ThirdViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"appBackgroundColor.png"]];

    [self.view addSubview:self.findUsScrollView];
}

-(void)viewWillAppear:(BOOL)animated{

    //this line creates the frame of the scrollview (dimensions)
    [self.findUsScrollView setFrame:CGRectMake(0, 0, 0, 750)];
    [super viewWillAppear:animated];
}

-(void)viewDidAppear:(BOOL)animated
{
    //dimensions of content within scrollveiw. Scrolling enabaled.
    [self.findUsScrollView setScrollEnabled:YES];
    [self.findUsScrollView setContentSize:CGSizeMake(0, 751)];
    [super viewWillAppear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)callButton:(id)sender {

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:0000000000"]];
}

- (IBAction)getDirButton:(id)sender {

}

@end

这是地图视图的.h文件:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface MyMapViewController : UIViewController <MKMapViewDelegate, MKAnnotation>

@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (weak, nonatomic) IBOutlet UINavigationBar *titleBarMap;
@property (weak, nonatomic) IBOutlet UIToolbar *bottomNavBarMap;
@property (weak, nonatomic) IBOutlet UIView *topTitlesOverlay;
- (IBAction)backButtonMap:(id)sender;

@end

这是地图视图的.m文件:

#import "MyMapViewController.h"

@implementation BountMapViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (IBAction)backButtonMap:(id)sender {

    [self dismissViewControllerAnimated:YES completion: ^(void){
    ThirdViewController *vc = (ThirdViewController *)[self presentingViewController];
    [[vc findUsScrollView] becomeFirstResponder];

}];
}

@end

2 个答案:

答案 0 :(得分:0)

尝试将[self.findUsScrollView setFrame:CGRectMake(0, 172, 320, 680)];[self.findUsScrollView setContentSize:CGSizeMake(320, 680)];移至viewDidLoad作为第一个建议。您不希望每次出现视图时都调用它们。

其次,您的contentSize和frameSize是相同的(320,680)。这意味着您的UIScrollView不需要滚动。请记住:要使UIScrollView滚动它的内容大小必须更大而不是它的帧大小。这应该是全部,当然:setScrollEnabled: YES;

答案 1 :(得分:0)

您对viewDidAppear的覆盖正在调用[super viewWillAppear:]而不是[super viewDidAppear:]