2012-03-29 4 views
1

HTML <marquee> 태그와 같은 MARQUEE 효과가있는 UIView를 두 개 이상 만들어야합니다.iphone에서 마키 효과가있는 하나 이상의 uiview를 만드는 방법

먼저 동적으로 UIView를 만들어야합니다.

동적으로 생성 된 UIView에 MARQUEE 효과를 추가 한 후.

도움이 될 것입니다.

+0

두 가지 : 질문이 명확하지 않으며 무엇을 시도 했습니까? –

+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

관련 문제