2011-07-21 4 views

答えて

2

いずれのアプリ(ゲームLudite)にも精通していませんが、画面の幅を画面の幅より大きくすると、その位置/中心/フレーム/変換/などを移動できます。それを動かすために、あなたはその行動をアニメートすることもできます。

最後の320ポイントに等しいビューの幅の最初の320ポイント(ポイントではなくピクセルで測定)を作成すると、ビューの位置が最後に達したときにジャンプして永遠に進むことができます。


編集(例えば、コード):

- (void)animateBannerLocation { 
    UIView *view = _bannerView; // _bannerView.frame = CGRectMake(0,0,1000 ish,40); 
    CGRect startRect = view.frame; 
    CGRect destinationRect = view.frame; 
    // assuming superview is width of screen 
    destinationRect.origin.x = CGRectGetWidth(view.frame) - CGRectGetWidth(view.superview.frame); 
    [UIView animateWithDuration:6.0 // time in seconds 
        animations:^(void) { 
        view.frame = destinationRect; 
        } completion:^(BOOL finished) { 
        /** if you want it to scroll forever: 
        view.frame = startRect; 
        [self animateBannerLocation]; 
         **/ 
        }]; 
} 

未試験


- (void)viewDidLoad { 
    [super viewDidLoad]; 
    UIImageView *_bannerView; /// - an ivar 
    // not the best way to load an image you only use in one place: 
    UIImage *image = [UIImage imageNamed:@"SomeBigBannerImage1000x40ish.png"]; 
    _bannerView = [[UIImageView alloc] initWithImage:image]; 
    [self.view addSubview:_bannerView]; 
} 

もテストされていない編集#2

編集#3

コードを確認しました。コンパイラの警告に注意する必要があります。

- (void)animateBannerLocation { 
    UIView *view = _bannerView; // _bannerView.frame = CGRectMake(0,0,1000 ish,40); 
    CGRect startRect = view.frame; 
    CGRect destinationRect = view.frame; 
    // assuming superview is width of screen 
    destinationRect.origin.x = - (CGRectGetWidth(view.frame) - CGRectGetWidth(view.superview.frame)); 
    [UIView animateWithDuration:6.0 
         delay:0.0 
         options:UIViewAnimationOptionCurveLinear 
        animations:^(void) { 
        view.frame = destinationRect; 
        } completion:^(BOOL finished) { 
        view.frame = startRect; 
        if (stopAnimation == NO) 
         [self animateBannerLocation]; 
        }]; 

} 


- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    [self animateBannerLocation]; 
} 
+0

ビューを移動することをおすすめしますか?あなたが見ることができるサンプルコードまたはサイトを提供できますか?また、終わりに達した後、最初の320ピクセルに戻すようにビューを設定するにはどうすればよいですか? – MacN00b

+0

私はこのコードは動作すると思いますが、修正する方法がわからないというエラーが1つあります。私は_bannerViewの代わりに何を置くべきですか?私はxibファイル内のビューを自動的に持つ通常のView Controllerを使用しています。だから私は_bannerViewの代わりに何を置くべきですか? ?すべての助けをありがとう、ごめんなさい、私は少しばかだと思います。 – MacN00b

+0

私は仕事の第二の方法を得ました。しかし、画像はスクロールしていません。私は両方の方法を一緒に使うはずですか? – MacN00b

関連する問題