Ich baue eine App auf der Grundlage der "Scrolling" Beispielcode, die Apple zur Verfügung gestellt. Alles funktioniert sehr gut. Die Art der Bilder, die ich anzeigen möchte, würde es wünschenswert machen, wenn die Reihenfolge der Bilder umgekehrt ist und das erste sichtbare Bild am weitesten rechts und nicht am weitesten links ist. Grundsätzlich sollte der Benutzer von rechts nach links und nicht von links nach rechts zurückrollen. Aber jetzt: Ich verstehe nicht die Syntax, die Apple verwendet, und ich hoffe, dass mir jemand erklären kann, was los ist. Hier sind die relevanten Teile der Beispiel-App:iphone UIScrollView umgekehrte Reihenfolge Positionierung
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor whiteColor];
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i; // tag our images for later use when we place them in serial fashion
[scrollView1 addSubview:imageView];
[imageView release];
}
[self layoutScrollImages]; // now place the photos in serial layout within the scrollview
}
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}
Mit welchem Teil der Syntax haben Sie Probleme? – diederikh
Es ist im Grunde das CG-bezogene Zeug. Ich habe versucht, nur "für (i = 1; i <= kNumImages; i ++)" in "für (i = kNumImages; i => 1; i--)" zu ändern, aber im Kontext meiner App hat das unerwartete Ergebnisse geliefert Ergebnisse. Darüber hinaus löst es mein Problem nicht, wie man den letzten "Rahmen" zeigt. – Sjakelien