добавление отражения в iCarousel - PullRequest
0 голосов
/ 15 февраля 2012

Я попытался добавить отражение в мою 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;

}

Отражение появляется.Но проблема в том, что когда я перемещаю представление карусели, изображения не текут правильно.Иногда появляется другой вид карусели.

У вас есть идеи, что вызывает это?

Ответы [ 3 ]

1 голос
/ 15 февраля 2012

Код должен быть:

- (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;
}
0 голосов
/ 16 февраля 2012

Я нашел свою ошибку.Я загружаю изображения здесь: - (void) getImagesWithThread {NSAutoreleasePool * pool;pool = [[NSAutoreleasePool alloc] init];

//for(int i=0;i<bookCount;i++){
for(int i=0;i<bookCount;i++){   

    NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:      [arrBookImages objectAtIndex:i]]];
    UIImage *image = [[UIImage imageWithData: imageData] retain];

    image = [self scaleToSize:CGSizeMake(140, 200) withImage:image];

    if(image!=nil) [arrBookImages replaceObjectAtIndex:i withObject:image];



    [image release]; }

[carousel reloadData];

[сток бассейна];

} Когда я выполнял это в фоновом режиме, он не перезагружался правильно.Если я выполняю нормально, это работает.Но я хочу загрузить их в потоке.Я имею в виду сначала я хочу установить изображения и заменить их изображения из URL.но я хочу, чтобы они появлялись один за другим.У тебя есть идеи?

0 голосов
/ 15 февраля 2012

Я использую изображения со встроенным отражением ... мне не нужно ничего делать в коде таким образом ...: p

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...