我正在尝试以编程方式将 UIButton 添加到我的滚动视图中。按钮在屏幕上弹出,但无法点击...
这是我的代码(viewDidLoad):
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(showAlert:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Enter app" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
self.view.backgroundColor = COLOR_BG;
self.view.clipsToBounds = YES;
CGRect scrollFrame;
scrollFrame.origin.x = 0;
scrollFrame.origin.y = 0;
scrollFrame.size.width = self.view.frame.size.width + 500;
scrollFrame.size.height = self.view.frame.size.height + 500;
self.scrollView = [[[UIScrollView alloc] initWithFrame:scrollFrame] autorelease];
self.scrollView.backgroundColor = COLOR_BG;
self.scrollView.bounces = YES;
self.scrollView.delegate = self;
self.scrollView.userInteractionEnabled = YES;
self.scrollView.exclusiveTouch = YES;
_scrollView.delaysContentTouches = NO;
_scrollView.canCancelContentTouches = NO;
self.slideImages = [[[NSMutableArray alloc] init] autorelease];
int rows = 8;
int total_count = 8;
for (int i = 0; i < total_count;i++) {
ImageRenderView *imageView = [[ImageRenderView alloc] initWithFrame:CGRectMake(i * (SIZE+LEFT_EDGE_OFSET), 0, SIZE + LEFT_EDGE_OFSET, SIZE * rows)];
[self.scrollView addSubview:imageView];
[self.slideImages addObject:imageView];
[imageView release];
}
[self.scrollView setContentSize:CGSizeMake(WIDTH_OF_SCROLL_PAGE, self.scrollView.frame.size.height)];
[self.scrollView setContentOffset:CGPointMake(0, 0)];
self.gradient = [CAGradientLayer layer];
self.gradient.frame = self.scrollView.bounds;
self.gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor], (id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:0] CGColor], nil];
self.gradient.startPoint = CGPointMake(0.1, 0.5);
self.gradient.endPoint = CGPointMake(0.9, 0.5);
[self.view addSubview:self.scrollView];
[self.scrollView scrollRectToVisible:CGRectMake(WIDTH_OF_IMAGE*2,0,WIDTH_OF_IMAGE,self.scrollView.frame.size.height) animated:NO];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(scrollView1:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
[self.scrollView.layer addSublayer:self.gradient];
[self makePerspective];
self.scrollView.alpha = 0.0;
////
CC_DIRECTOR_END();
// Create an CCGLView with a RGB8 color buffer, and a depth buffer f 0-bits
CCGLView *glView = [CCGLView viewWithFrame:[[UIScreen mainScreen] bounds]
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
director_ = (CCDirectorIOS*)[CCDirector sharedDirector];
director_.wantsFullScreenLayout = YES;
// Display Milliseconds Per Frame
[director_ setDisplayStats:YES];
// set FPS at 60
[director_ setAnimationInterval:1.0/60];
// attach the openglView to the director
[director_ setView:glView];
// 3D projection
[director_ setProjection:kCCDirectorProjection3D];
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director_ enableRetinaDisplay:YES] )
CCLOG(@"Retina Display Not supported");
UINavigationController *navController_ = [[[UINavigationController alloc] initWithRootViewController:director_] autorelease];
navController_.navigationBarHidden = YES;
[director_ setDelegate:nil];
[self.view addSubview:navController_.view];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:YES];
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];
[sharedFileUtils setiPadSuffix:@"-ipad"];
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];
movingBlockVC = [[MovingBlockContainer alloc] initWithNibName:nil bundle:nil];
[movingBlockVC view];
CGRect old = movingBlockVC.view.frame;
[self.view addSubview:movingBlockVC.view];
movingBlockVC.view.frame = CGRectMake(-old.size.width, -old.size.height, old.size.width, old.size.height);
movingBlockVC.view.hidden = YES;
[self.view sendSubviewToBack:movingBlockVC.view];
director_.view.hidden = YES;
}
有人可以帮我解决这个问题吗?或者只是解释我做错了什么?