我做了一个Xcode项目的选项卡式应用程序,显示滚动视图中的色板图像。如何链接我的滚动视图中的一个图像以转到下一个视图控制器?以下是我的代码和图片。因此,当您在滚动视图中点击其中一幅图像或色板颜色时,它会链接到新控制器。Xcode图像链接ImageView到下一个视图控制器
我有多个图像向下滚动的iPhone页面,我必须循环图像,因为有24个图像。我是能够使一个按钮,并将其链接到与界面生成器的下一个场景,但我可以适应屏幕上的5张..
DecorsViewController_iPhone.h
#import <UIKit/UIKit.h>
@interface DecorsViewController_iPhone : UIViewController
{
IBOutlet UIScrollView *scrollViewDecors;
}
@property (nonatomic, retain) UIView *scrollViewDecors;
@end
DecorsViewController_iPhone.m
#import "DecorsViewController_iPhone.h"
@interface DecorsViewController_iPhone()
@end
@implementation DecorsViewController_iPhone
@synthesize scrollViewDecors;
const CGFloat kScrollObjHeight = 81.5;
const CGFloat kScrollObjWidth = 320.0;
const NSUInteger kNumImages = 24;
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollViewDecors subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
CGFloat curYLoc = 0;
CGFloat curYSpace = 1;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, curYLoc);
view.frame = frame;
curYLoc += (curYSpace + kScrollObjHeight);
}
}
// set the content size so it can be scrollable
[scrollViewDecors setContentSize:CGSizeMake(([scrollViewDecors bounds].size.width), (kNumImages * kScrollObjHeight))]; // Vertical Option
}
- (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
[scrollViewDecors setBackgroundColor:[UIColor blackColor]];
[scrollViewDecors setCanCancelContentTouches:NO];
scrollViewDecors.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollViewDecors.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollViewDecors.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:@"Artwork_iPhone_Decors_Scrollview_%d.png", 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
[scrollViewDecors addSubview:imageView];
//[imageView release];
}
[self layoutScrollImages]; // now place the photos in serial layout within the scrollview
}
//- (void)dealloc
//{
// [scrollViewDecors release];
//
// [super dealloc];
//}
//- (void)viewDidLoad
//{
// [super viewDidLoad];
// // Do any additional setup after loading the view, typically from a nib.
//}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
我怎么会让一个透明的按钮在我的每个图像上转到一个新的视图控制器,我有24个滚动的图像。我可以使用界面生成器制作一个按钮,并将它与翻转模式链接起来,它可以工作,但是我只能对5张图像做屏幕高度,我有24张图像,这就是为什么我需要它滚动的原因。我是Xcode的新手。 –
我不明白你为什么不只是使用UITableView?对于你想要达到的目标来说,这看起来很完美?只需使用cellForRowAtIndexPath填充数组,然后使用didSelectRowAtIndexPath来确定选择了哪种颜色/单元格,从而确定显示哪个视图。 –
我是Xcode的新手,我不确定如何填充tableview以反映我自己的自定义图像,以及如何将表链接到新视图。我能够轻松地制作标签页,但是在使用滚动视图时会卡住。我拥有的图像数量的原因。 –