升级到 iOS7/xcode 5 后 UIScrollView 不滚动 [英] UIScrollView doesn't scroll after upgrading to iOS7 / xcode 5
问题描述
我有一个应用程序,它在 xcode 4.5 和 ios 6.1 中滚动时运行良好.但是,在下载 xcode 5 和 iOS 7 后,我的滚动视图不再起作用了.???
I have an app which in xcode 4.5 and ios 6.1 worked perfectly fine when scrolling. However, after downloading xcode 5 and iOS 7 my scroll views does not work anymore.???
这是我的 .h 文件:
Here is my .h file:
#import <UIKit/UIKit.h>
@interface GrillretterViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIScrollView *grillretterScroller;
@property (assign) CGPoint rememberContentOffset;
@end
这是我的 .m 文件:
And here is my .m file:
#import "GrillretterViewController.h"
@interface GrillretterViewController ()
@end
@implementation GrillretterViewController
@synthesize grillretterScroller, rememberContentOffset;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[grillretterScroller setScrollEnabled:YES];
// Do any additional setup after loading the view.
}
- (void) viewDidAppear:(BOOL)animated {
[grillretterScroller setContentSize:CGSizeMake(300, 915)];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
self.grillretterScroller.contentOffset = CGPointMake(0, 0);
}
- (void)viewWillDisappear:(BOOL)animated {
self.rememberContentOffset = self.grillretterScroller.contentOffset;
[super viewWillDisappear:animated];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.grillretterScroller.contentOffset = CGPointMake(0, self.rememberContentOffset.y);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
请帮忙!我卡住了!
最好的问候!
推荐答案
我通过在滚动视图的主视图的文件检查器窗格中取消选择使用自动布局"解决了这个问题.
I solved this by deselecting 'Use Autolayout' in the File Inspector pane of main view within the Scroll View.
如果您想保持自动布局"启用,请尝试编辑器 -> Reslove Autolayout Issues -> Add Missing Constraints".关键约束似乎是底部空间到:超级视图,在我的例子中是 -300,在视图底部提供 300 滚动空间.
If you want to keep 'Autolayout' enabled, try 'Editor -> Reslove Autolayout Issues -> Add Missing Constraints'. The key constraint appears to be 'Bottom Space to: Superview and in my case was -300, giving 300 scroll space on the botton of the view.
这篇关于升级到 iOS7/xcode 5 后 UIScrollView 不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!