几天前我开始开发iOS,所以对我来说一切都是新的! 我需要在应用程序中显示“照片滑块”,就像我们在iPhone库或Facebook应用程序中一样。 经过一番研究,我达到了死胡同。我的目标是逐个展示一组照片,让用户从右向左滑动手指,反之亦然:-)iPhone显示照片/图片滑动(如照片库和Facebook应用程序)?
有没有人有一个例子或知道一个?
感谢所有。
几天前我开始开发iOS,所以对我来说一切都是新的! 我需要在应用程序中显示“照片滑块”,就像我们在iPhone库或Facebook应用程序中一样。 经过一番研究,我达到了死胡同。我的目标是逐个展示一组照片,让用户从右向左滑动手指,反之亦然:-)iPhone显示照片/图片滑动(如照片库和Facebook应用程序)?
有没有人有一个例子或知道一个?
感谢所有。
好Three20是有名的,但我会使用它阻止你。如果您只需要一个照片滑块,然后将整个Three20框架放入您的项目中,并试图弄清楚基于URL的导航工具的工作原理可能是一个真正的痛苦。
这是一个更好的选择,https://github.com/enormego/PhotoViewer。它是独立实现的照片滑块和相应的图像缓存。您可以阅读更多关于代码如何在作者博客http://developers.enormego.com/上工作的信息。
,如果你想看看有“照片滑块”在Three20 - https://github.com/facebook/three20/tree/master/samples/TTCatalog - 只需下载源代码,并建立TTCatalog
你可以使用下面的示例代码进行图像幻灯片..这里'scr'是scrollview对象。在yhpets响应
NSMutableArray *imgs=[[NSMutableArray alloc]init];
// arrayWithObjects:[UIImage @"abc1.jpg"],[UIImage @"abc2.jpg"],[UIImage @"abc3.jpg"], [[email protected]"abc4.jpg"],
// [ UIImage @"abc5.jpg"],nil];
[imgs addObject:[UIImage imageNamed:@"abc1.jpg"]];
[imgs addObject:[UIImage imageNamed:@"abc2.jpg"]];
[imgs addObject:[UIImage imageNamed:@"abc3.jpg"]];
[imgs addObject:[UIImage imageNamed:@"abc4.jpg"]];
[imgs addObject:[UIImage imageNamed:@"abc5.jpg"]];
for(int i=0;i<imgs.count;i++)
{
CGRect frame;
frame.origin.x=self.scr.frame.size.width *i;
frame.origin.y=0;
frame.size=self.scr.frame.size;
UIImageView *subimg=[[UIImageView alloc]initWithFrame:frame];
subimg.image=[imgs objectAtIndex:i];
[self.scr addSubview:subimg];
[subimg release];
self.scr.contentSize=CGSizeMake(self.scr.frame.size.width*imgs.count, self.scr.frame.size.height);
}
大厦,这支持方向通过应用标签每个ImageView的和使用它们引用每个ImageView的,当设备旋转调整也改变...
在你ViewController.h文件你需要设置你的阵列和滚动型...
@interface ViewController : UIViewController{
NSMutableArray *imgs;
IBOutlet UIScrollView *scr;
}
@property (strong, nonatomic) IBOutlet UIScrollView *scr;
而在你ViewController.m,你需要听didRotateFromInterfaceOrientation和调整ImageViews,以适应新的屏幕。我们需要根据纵向或横向来设置screenWidth和screenHeight变量,并使用这些来调整每个图像视图和滚动视图的大小。
@implementation ViewController
@synthesize scr;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
if ((self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)||(self.interfaceOrientation == UIInterfaceOrientationPortrait)){
//screenWidth and screenHeight are correctly assigned to the actual width and height
}else{
screenHeight = screenRect.size.width;
screenWidth = screenRect.size.height;
screenRect.size.width = screenWidth;
screenRect.size.height = screenHeight;
}
NSLog(@"see it's right now= (%f,%f)",screenWidth,screenHeight);
self.scr.contentSize=CGSizeMake(screenWidth*imgs.count, screenHeight);
for(int i=0;i<imgs.count;i++){
UIImageView *targetIV = (UIImageView*)[self.view viewWithTag:(i+1)];
CGRect frame;
frame.origin.x=screenWidth *i;
frame.origin.y=0;
frame.size=CGSizeMake(screenWidth, screenHeight);
targetIV.frame = frame;
}
}///////////////////////////////////////////////////////////////////////////
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
imgs=[[NSMutableArray alloc]init];
[imgs addObject:[UIImage imageNamed:@"1001.png"]];
[imgs addObject:[UIImage imageNamed:@"1002.png"]];
[imgs addObject:[UIImage imageNamed:@"1003.png"]];
[imgs addObject:[UIImage imageNamed:@"1004.png"]];
for(int i=0;i<imgs.count;i++){
CGRect frame;
frame.origin.x=self.scr.frame.size.width *i;
frame.origin.y=0;
frame.size=self.scr.frame.size;
UIImageView *subimg=[[UIImageView alloc]initWithFrame:frame];
subimg.image=[imgs objectAtIndex:i];
subimg.tag = (i+1);
subimg.contentMode = UIViewContentModeScaleAspectFit;
[self.scr addSubview:subimg];
}
self.scr.contentSize=CGSizeMake(self.scr.frame.size.width*imgs.count, self.scr.frame.size.height);
}
是的,我想说的是关于Three20的同样的事情。基于URL的导航是一个真正的痛苦。 – timothy5216 2011-01-24 01:28:03