自动ScrollView

时间:2012-11-03 16:48:57

标签: objective-c xcode

是否有自动滚动视图的解决方案?我有多个图像。例如:第一张图片是320 x 10000,第二张是320 8000.

我有这段代码。

这是DataManager:

<code>
#import "DataManager.h"

@interface DataManager ()

@property (nonatomic, strong) NSArray * myArr;
@property (nonatomic, strong) NSArray * myArrTitoli;

@end

@implementation DataManager

static DataManager *sharedClassInstance = nil;

+ (DataManager *)sharedClass {
    @synchronized(self) {
        if (!sharedClassInstance)
            sharedClassInstance = [[DataManager alloc] init];
        return sharedClassInstance;
    }
}

- (void)setupDM {
    UIImage * img1 = [UIImage imageNamed:@"Storia1.png"];
    UIImage * img2 = [UIImage imageNamed:@"Storia1.png"];

self.myArr = @[img1, img2];


    UIImage * button1 = [UIImage imageNamed:@"storia_1_button.png"];
    UIImage * button2 = [UIImage imageNamed:@"storia_2_button.png"];
    UIImage * button3 = [UIImage imageNamed:@"storia_3_button.png"];

    self.myArrTitoli = @[button1, button2, button3];

}

- (int)productsCount {
    return self.myArrTitoli.count;
}

- (UIImage*)imageForRow:(int)row {
    return self.myArr[row];
}

- (UIImage*)buttonForRow:(int)row {
    return self.myArrTitoli[row];
}

@end

</code>

我有一个选择底部的表格视图。这是一个故事的UiViewController。

#import "StoryViewController.h"

@interface StoryViewController ()
@property (strong, nonatomic) IBOutlet UIImageView *storyImage;

@end

@implementation StoryViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.storyImage.image = self.ponteImage;

    [scroller setScrollsToTop:NO];
    [scroller setContentSize:CGSizeMake(320, 10000)];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

但这种方法不起作用。

你能帮帮我吗?如果存在10000像素或8000或6000的图像,我想要自动滚动视图。

谢谢。

1 个答案:

答案 0 :(得分:0)

  1. 检查您是否已连接IBOutlet

  2. 滚动定义位置使用:

    [self.scrollView setContentOffset:CGPointMake(positionX,0)];