0

如何将溶解过渡添加到我的代码中?

我尝试查看 Apple 的代码,但无济于事。有任何想法吗?

#import "ApotheosisViewController.h"

@implementation ApotheosisViewController

@synthesize scrollView1;

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

const CGFloat kScrollObjHeight = 320.0;
const CGFloat kScrollObjWidth = 480.0;
const NSUInteger kNumImages  = 40;


- (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)];
}

- (void)viewDidLoad
{
 self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];

 // 1. setup the scrollview for multiple images and add it to the view controller
 //
 // note: the following can be done in Interface Builder, but we show this in code for clarity
 [scrollView1 setBackgroundColor:[UIColor blackColor]];
 [scrollView1 setCanCancelContentTouches:NO];
 scrollView1.indicatorStyle = UIScrollViewIndicatorStyleBlack;
 scrollView1.clipsToBounds = NO;  // default is NO, we want to restrict drawing within our scrollview
 scrollView1.scrollEnabled = YES;

 // pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
 // if you want free-flowing scroll, don't set this property.
 scrollView1.pagingEnabled = YES;

 // 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)dealloc
{ 
 [scrollView1 release];

 [super dealloc];
}

- (void)didReceiveMemoryWarning
{
 // invoke super's implementation to do the Right Thing, but also release the input controller since we can do that 
 // In practice this is unlikely to be used in this application, and it would be of little benefit,
 // but the principle is the important thing.
 //
 [super didReceiveMemoryWarning];
}

@end
4

1 回答 1

0

我无法立即说出您发布的代码与溶解过渡有什么关系。

如果您试图从一个视图转到另一个视图,那么您可以将其放入您的代码中:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

对于一个视图控制器:

    self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

当从一个视图切换到另一个视图时:

    [self presentModalViewController:otherViewController animated:YES];
于 2009-09-07T11:01:57.480 回答