I'm trying to make a scroll view in xcode. I used the following code in xcode 5 (which worked):
view.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
IBOutlet UIScrollView *ScrollView;
}
@end
view.m
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[ScrollView setScrollEnabled:YES];
[ScrollView setContentSize:CGSizeMake(320, 1005)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
I have seen others with this problem but none of their solutions worked for me. Note that i have size set to freedom and auto layout is turned off.
Due to a scrollView feature in auto layout, the contentSize is being redefined. To solve this problem, you could disable auto layout or set the content size in viewDidLayoutSubviews()
-(void)viewWillLayoutSubviews {
[super viewDidLayoutSubviews];
ScrollView.contentSize = CGSizeMake(320,1005);
}
So you would want to add this code and delete the ScrollView.contentSize method in viewDidLoad.
I don't see anything immediately wrong with this code. I would check and makes sure that you've connected the IBOutlet properly in the Interface Builder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.