我有一个UIView
(当然是在视图控制器内部),在这个内部UIView
,我有一个UIScrollView
. UIScrollView
包含一些图像和按钮。其中一个按钮使用模态 Action Segue 并打开一个UIView
带有MapView
内部的按钮,并在底部打开一个“返回”按钮,将您带回上一个UIView
。但是在“返回”(从MapView
到UIView
)时,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