ios - 在 Xcode 4.6 中使用 UIScrollView

标签 ios uiscrollview storyboard

我正在使用 Storyboards,并且我创建了一个 UIScrollView 及其 socket :
.h

@interface ViewController : UIViewController <UIScrollViewDelegate>
    @property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@end
.m :我合成了scrollView,在viewDidLoad上我有
- (void)viewDidLoad { 
[super viewDidLoad];
self.scrollView.delegate = self;

// Init an array with 3 images
subviewArray = [[NSMutableArray alloc] initWithObjects:@"image1.jpg", @"image2.jpg", @"image3.jpg", nil];

for (int i = 0; i < [subviewArray count]; i++) {
    //We'll create a View object in every 'page' of our scrollView.
    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * i;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
    imageView.image = [UIImage imageNamed:[subviewArray objectAtIndex:i]];
    [self.scrollView addSubview:imageView];
}

NSLog(@"%f", self.scrollView.frame.size.width);

//Set the content size of our scrollview according to the total width of our imageView objects.
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [subviewArray count], self.scrollView.frame.size.height);
}

问题是当我打印“self.scrollView.frame.size.width”的值时,我得到“0”!
任何帮助请!

最佳答案

修复它,我不得不取消选中文件检查器中的“使用自动布局”。非常感谢韦恩!希望这可以帮助其他人。祝你好运 !

关于ios - 在 Xcode 4.6 中使用 UIScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16251679/

相关文章:

ios - 包含两个信息数组的 TableView

xcode - 如何在 ScrollView 中使用自动布局?

iphone - 当键盘显示时向上移动 UIView

ios - 单个场景中的多个 View Controller ?

ios - "CoreData: error: NULL _cd_rawData but the object is not being turned into a fault"

ios - 在 UITableView 上出队和重新排队时,MKMapView 不断缩小

ios - 如何动画和旋转按钮

ios - 关于 UIScrollView 作为启用 UIPanGesture 的 View 的 subview 的问题

ios - 从 Modal/Popover 展开 Segue,导致对开始/结束外观转换的调用不平衡

c# - WPF动画: How to slide between multiple elements within a stackpanel?