gpt4 book ai didi

iphone - 向 iCarousel 添加反射

转载 作者:行者123 更新时间:2023-11-29 04:48:18 25 4
gpt4 key购买 nike

我尝试为我的 icarousel 添加反射。首先,我的代码是这样的,并且工作正常。

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index     reusingView:(UIView *)view
{
UIButton* button = (UIButton *)view;
if (button == nil)
{
//no button available to recycle, so create new one
UIImage *image = [arrKitapKapaklari objectAtIndex:index];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
[button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
[button setBackgroundImage:image forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
}


//set button label
[button setTitle:[NSString stringWithFormat:@"%i", index] forState:UIControlStateNormal];

return button;

}

更改后,我的代码变成了这样:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(ReflectionView *)view
{


UIButton* button = nil;
if (button == nil)
{

view = [[[ReflectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 200.0f)] autorelease];
//no button available to recycle, so create new one
UIImage *image = [arrKitapKapaklari objectAtIndex:index];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
[button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
[button setBackgroundImage:image forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
}



//set button label
[button setTitle:[NSString stringWithFormat:@"%i", index] forState:UIControlStateNormal];
[view update];
return view;

}

出现倒影。但问题是当我移动轮播 View 时,图像无法正确流动。有时会出现另一个轮播 View 。

你知道是什么原因造成的吗?

最佳答案

代码应该是:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(ReflectionView *)view
{


UIButton* button = nil;
if (view == nil)
{
//no view available to recycle, so create new one
view = [[[ReflectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 200.0f)] autorelease];

button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = view.bounds;
[button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
button.tag = 99;
[view addSubview:button];
}
else
{
button = (UIButton *)[view viewWithTag:99];
}

//set button label
[button setTitle:[NSString stringWithFormat:@"%i", index] forState:UIControlStateNormal];

UIImage *image = [arrKitapKapaklari objectAtIndex:index];
[button setBackgroundImage:image forState:UIControlStateNormal];

[view update];
return view;
}

关于iphone - 向 iCarousel 添加反射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9295772/

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