gpt4 book ai didi

ios - UIButton 在 ScrollView 上不可点击

转载 作者:行者123 更新时间:2023-11-29 03:36:00 25 4
gpt4 key购买 nike

我正在尝试以编程方式将 UIButton 添加到我的 ScrollView 上。按钮在屏幕上弹出,但无法点击...

这是我的代码(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;

}

有人可以帮我解决这个问题吗?或者只是解释一下我做错了什么?

最佳答案

不确定,但看起来您将按钮添加到 View 中,然后将 ScrollView 添加到按钮顶部的 View 中;这意味着任何触摸事件都将出现在 ScrollView 中,而不是按钮中。

如果我的假设是正确的,您应该在启动和配置后将按钮添加到 ScrollView 。

关于ios - UIButton 在 ScrollView 上不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19168382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com