2

我有一个UIView(当然是在视图控制器内部),在这个内部UIView,我有一个UIScrollView. UIScrollView包含一些图像和按钮。其中一个按钮使用模态 Action 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
4

2 回答 2

0

您的替代viewDidAppear是调用[super viewWillAppear:]而不是[super viewDidAppear:]

于 2012-11-30T06:55:12.997 回答
0

Try moving [self.findUsScrollView setFrame:CGRectMake(0, 172, 320, 680)]; and [self.findUsScrollView setContentSize:CGSizeMake(320, 680)]; to viewDidLoad as a first suggestion. You don't want those to be called everytime your view appears.

Second, your contentSize and frameSize are the same (320, 680). This means your UIScrollView does not need to scroll. Remember: for a UIScrollView to scroll it's content size must be bigger than it's frame size. That should be all, and of course: setScrollEnabled: YES;

于 2012-11-30T01:29:16.387 回答