2012-03-17 9 views
0

私は私のスライドショーにトランジション効果を追加しようとしている:ここで私は私がスライドショーにトランジション効果を追加

[UIView transitionFromView:currentView toView:nextView duration:1.0 
options:UIViewAnimationOptionTransitionCrossDissolve completion:nil]; 

を使うべきだと思う私のコード

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
photos = [[NSMutableArray alloc] init]; 

NSXMLParser *photoParser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL 
URLWithString:@"http://localhost/index.xml"]]; 
[photoParser setDelegate:(id)self]; 
[photoParser parse]; 

currentImage = 0; 

NSURL *imageURL = [NSURL URLWithString:[photos objectAtIndex:0]]; 
NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; 
[imgView setImage:[UIImage imageWithData:imageData]]; 

timer = [NSTimer scheduledTimerWithTimeInterval: 0.5 
             target: self 
             selector: @selector(handleTimer:) 
             userInfo: nil 
             repeats: YES]; 
} 

- (void) handleTimer: (NSTimer *) timer { 
currentImage++; 
if (currentImage >= photos.count) 
    currentImage = 0; 

NSURL *imageURL = [NSURL URLWithString:[photos objectAtIndex:currentImage]]; 
NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; 
[imgView setImage:[UIImage imageWithData:imageData]]; 
} 

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
attributes:(NSDictionary *)attributeDict { 
if ([elementName isEqualToString:@"photo"]) { 
    [photos addObject:[attributeDict objectForKey:@"url"]]; 
} 
} 

だが、私はありませんどのように行いますtransitionFRomView:およびtoView:フィールドに入力します。私は1つのビューのみに

+0

私は今それをテストすることはできませんが、できるだけ早く私はあなたに知らせます。助けてくれてありがとう – Enzoses

答えて

0

あなたはdocumentationが言うどの方法transitionWithView:duration:options:animations:completion:を使用することができますあなたの助け

感謝を持っている:あなたはサブビューを追加、削除、ショー、または非表示にするには、このブロックを使用することができます

指定されたビューの

これは、あなたがそのメソッドを使用する方法の例です:

- (void) handleTimer: (NSTimer *) timer { 
    currentImage++; 
    if (currentImage >= photos.count) currentImage = 0; 

    NSURL *imageURL = [NSURL URLWithString:[photos objectAtIndex:currentImage]]; 
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL] 
    [UIView transitionWithView:containerView 
     duration:2 
     options:UIViewAnimationOptionTransitionFlipFromLeft 
     animations:^{ 
      [imgView removeFromSuperview]; 
      imgView = // create a new image view 
      [imgView setImage:[UIImage imageWithData:imageData]]; 
      [containerView addSubview:toView]; 
     } completion:NULL]; 
} 

containerViewimgViewの親ビューで、最も可能性の高いself.viewです。

+0

これは、containerViewをself.viewに置き換えるだけで動作します。imgView = [imgView setImage:[UIImage imageWithData:imageData]]; [imgView setImage:[UIImage imageWithData:imageData]];および[containerView addSubview:toView]; with [self.view addSubview:imgView];すばらしいです!プレゼンテーションをやり直す、転送する、一時停止するためのボタンを追加するにはどうすればよいですか?または別の質問を提出する必要がありますか? – Enzoses

+0

@Enzoses - どこのボタンを追加しますか?そして、他の質問でこれを尋ねると、より多くの情報を追加できるようになります。 – sch

+0

私は、ユーザーが写真をスキップするか、特定のものに戻るか、一時停止するかを決定するためのコントロールを表示したいと考えています。私はそれらを同じビューに配置する必要があると思います。あるいは、ボタンを使って "MainView"を作成し、その中にslideshowView – Enzoses