Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView in iOS 6

Recently i've downloaded Xcode 4.5(iOS 6),but when tried to continue one of my projects i noticed that the UIScrollView isn't working properly,let me explain more clearly:

I've created the UIScrollView and added the initialized it using the following code:

-(void)viewDidLoad{

    [mainScrollView setScrollEnabled:YES];
    mainScrollView.contentSize = CGSizeMake(480, 0);

    [super viewDidLoad];

}

After i opened my XIB and linked the mainScrollView to a UIScrollView,after i added some UIButton's to the scrollView.When i built the project the mainScrollView was scrolling but the buttons didn't showed up,i mean,i just could see the button that were already on the screen.What i'm doing wrong?How can i setup the UIScrollView?

like image 265
Mateus Avatar asked Jun 24 '12 23:06

Mateus


3 Answers

For xcode 4.5 ,If you are using scrollView you have to either uncheck "use AutoLayout" in file inspector.

or if you want to "use AutoLayout",then in .m(implementation) file add this

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    theScroller.contentSize=CGSizeMake(1024.0,1300.0);
}
like image 66
user1489709 Avatar answered Nov 16 '22 18:11

user1489709


Maybe you just typed this wrong, but your CGSize has a height of 0?

like image 4
Alexsander Akers Avatar answered Nov 16 '22 19:11

Alexsander Akers


You can do it with Auto Layout in XCode 4.5 But you config your UIScrollView in viewDidAppear

I do this also in a static UITableView with images.

Name your images like timg1.png, timg2.png....

in your ControllerView.h File

@property (weak, nonatomic) IBOutlet UIScrollView *Sv1;
@property (weak, nonatomic) IBOutlet UIPageControl *Pc1;

In your ControllerView.m File

-(void)viewDidAppear:(BOOL)animated
{

    //Scrollview
    Sv1.delegate = self;

    Sv1.contentSize = CGSizeMake(260, 176);

    [self.Sv1 setBackgroundColor:[UIColor clearColor]];
    // ScrollViewGarten.frame = CGRectMake(9, 11, 283, 170);
    [Sv1 setCanCancelContentTouches:NO];

    Sv1.multipleTouchEnabled = NO;
    Sv1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    Sv1.clipsToBounds = YES;
    Sv1.scrollEnabled = YES;
    Sv1.pagingEnabled = YES;

    NSUInteger nimagesTextil = 0;
    CGFloat cxTextil = 0;
    for (; ; nimagesTextil++) {
        NSString *imageNameTextil = [NSString stringWithFormat:@"timg%d.png", (nimagesTextil + 1)];
        UIImage *imageTextil = [UIImage imageNamed:imageNameTextil];
        if (imageTextil == nil) {
            break;
        }
        UIImageView *imageViewTextil = [[UIImageView alloc] initWithImage:imageTextil];

        CGRect rect = imageViewTextil.frame;
        rect.size.height = 176;
        rect.size.width = 260;
        rect.origin.x = ((Sv1.frame.size.width - imageTextil.size.width) / 2) + cxTextil;
        rect.origin.y = ((Sv1.frame.size.height - imageTextil.size.height) / 2);

        imageViewTextil.frame = rect;

        [Sv1 addSubview:imageViewTextil];

        cxTextil += Sv1.frame.size.width;
    }
    self.Pc1.numberOfPages = nimagesTextil;
    [Sv1 setContentSize:CGSizeMake(cxTextil, [Sv1 bounds].size.height)];
    self.Pc1.currentPage = 0;

}
like image 4
Frank M. Avatar answered Nov 16 '22 17:11

Frank M.