2012-03-29 13 views
1

にマーキー効果でダイナミックに複数のUIViewを作成するにはどうすればHTML <marquee>タグのようなMARQUEE効果を持つ複数のUIViewを作成する必要があります。はiphone

私は、最初の動的のUIViewを作成する必要があります。

後に動的に作成UIViewのためMARQUEE効果を追加します。

ご協力いただければ幸いです。

+0

2つのこと:あなたの質問は明確ではありません。 –

+0

私は動的にuiviewを作成しようとしていますが、動的なuiview ...リピートせずにhtml marqueeタグのように一度水平にuiviewを移動しようとしています! – Dinesh

+0

複数のビューを作成しているということですか?ビューには何があるのでしょうか? –

答えて

1

あなたはそれがゆっくりと右から左に、それらをスクロールして表示するビューの幅よりも広くなっている文字列のコレクションを表示することができますビューを意味していますか?あなたはそれを構築する必要があります。私は一度、UIScrollViewを次のようにサブクラス化することによって行いました:

// CrawlView.h 

#import <UIKit/UIKit.h> 

@interface CrawlView : UIScrollView 

@property (assign, nonatomic) NSTimeInterval period; 
@property (strong, nonatomic) NSMutableArray *messages; 

- (void)go; 

@end 


// CrawlView.m 

#import "CrawlView.h" 

// distance between neighboring strings. could make this a public property 
#define kPADDING 16.0 

@interface CrawlView() 

@property (assign, nonatomic) CGFloat messagesWidth; 

@end 

@implementation CrawlView 

@synthesize period=_period; 
@synthesize messages=_messages; 
@synthesize messagesWidth=_messagesWidth; 

- (void)buildSubviews { 

    for (UIView *subview in [self subviews]) { 
     if ([subview isKindOfClass:[UILabel self]]) { 
      [subview removeFromSuperview]; 
     } 
    } 

    CGFloat xPos = kPADDING; 

    for (NSString *message in self.messages) { 
     UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; 
     label.text = message; 
     CGSize size = [message sizeWithFont:label.font]; 
     CGFloat width = size.width + kPADDING; 
     label.frame = CGRectMake(xPos, 0.0, width, self.frame.size.height); 
     [self addSubview:label]; 
     xPos += width; 
    } 
    self.messagesWidth = xPos; 
    self.contentSize = CGSizeMake(xPos, self.frame.size.height); 
    self.contentOffset = CGPointMake(-self.frame.size.width, 0.0); 
} 

- (void)setMessages:(NSMutableArray *)messages { 

    if (_messages != messages) { 
     _messages = messages; 
     [self buildSubviews]; 
    } 
} 

- (void)go { 

    if (!self.period) self.period = self.messagesWidth/100; 
    // so it always takes about the same (fudged, but reasonable) amount of time to scroll the whole array 

    [UIView animateWithDuration:self.period 
          delay:0.0 
         options:UIViewAnimationOptionCurveLinear |UIViewAnimationOptionRepeat 
        animations:^{ 
         self.contentOffset = CGPointMake(self.messagesWidth, 0.0); 
        } completion:^(BOOL finished){}]; 
} 


@end 
+0

この関数を使用する方法...!この行にエラーが表示されます@プロパティ(強く非原子的)NSMutableArray * messages;エラーメッセージは不明です。 – Dinesh

+0

これはiOS SDK 5.1(ARCを使用)を対象としています。 OS5用にビルドできますか?もしそうでなければ、あなたはそれを「保持」するように変更することによってどのように動作するかを見ることができますが、それをそのようにしないでください。追加の作業をしない限り、メモリがリークします。 – danh

+0

いいえ私はiOS 4.3 SDK – Dinesh