我需要創建多個具有MARQUEE效果的UIView,如HTML <marquee>
標記。如何在iphone中創建多個具有選取框效果的uiview動畫
我首先需要動態創建UIView。
爲動態創建的UIView添加MARQUEE效果之後。
任何幫助將不勝感激。
我需要創建多個具有MARQUEE效果的UIView,如HTML <marquee>
標記。如何在iphone中創建多個具有選取框效果的uiview動畫
我首先需要動態創建UIView。
爲動態創建的UIView添加MARQUEE效果之後。
任何幫助將不勝感激。
您的意思是一個視圖,它可以顯示比視圖寬度更寬的字符串集合,它通過從右向左緩慢滾動顯示它?你需要建立它。我做了一次,像這樣繼承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
兩件事:你的問題不清楚,你有什麼試過? – 2012-03-29 05:19:19
我正在嘗試動態創建uiview,並且像html html選項標籤一樣水平移動uiview,而不必重複動態uiview ...! – Dinesh 2012-03-29 05:21:35
你的意思是你創建了多個視圖?觀點中會發生什麼? – 2012-03-29 05:22:41