Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iphone中创建具有字幕效果的动态多个uiview_Iphone_Ios_Uiview_Effect_Marquee - Fatal编程技术网

如何在iphone中创建具有字幕效果的动态多个uiview

如何在iphone中创建具有字幕效果的动态多个uiview,iphone,ios,uiview,effect,marquee,Iphone,Ios,Uiview,Effect,Marquee,我需要创建多个具有字幕效果的UIView,如HTML标记 我首先需要动态创建UIView 之后,为动态创建的UIView添加选框效果 如果有任何帮助,我们将不胜感激。您指的是一个视图,它可以通过从右向左缓慢滚动来显示比视图显示宽度更宽的字符串集合吗?你需要建造它。我曾经这样做过,通过如下子类化UIScrollView: // CrawlView.h #import <UIKit/UIKit.h> @interface CrawlView : UIScrollView @prop

我需要创建多个具有字幕效果的UIView,如HTML
标记

我首先需要动态创建UIView

之后,为动态创建的UIView添加选框效果


如果有任何帮助,我们将不胜感激。

您指的是一个视图,它可以通过从右向左缓慢滚动来显示比视图显示宽度更宽的字符串集合吗?你需要建造它。我曾经这样做过,通过如下子类化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
//CrawlView.h
#进口
@界面爬网视图:UIScrollView
@属性(赋值,非原子)NSTimeInterval期间;
@属性(强、非原子)NSMutableArray*消息;
-(无效)去;
@结束
//crawview.m
#导入“CrawlView.h”
//相邻字符串之间的距离。可以让这成为公共财产吗
#定义kp16.0
@界面爬网视图()
@属性(赋值,非原子)CGFloat messagesWidth;
@结束
@实现爬网视图
@合成周期=_周期;
@合成消息=_消息;
@合成messagesWidth=\u messagesWidth;
-(void)构建子视图{
对于(UIView*子视图在[自子视图]中){
if([subview iskindof类:[UILabel self]]){
[子视图从SuperView移除];
}
}
CGFloat xPos=kpos;
for(self.messages中的NSString*消息){
UILabel*label=[[UILabel alloc]initWithFrame:CGRectZero];
label.text=消息;
CGSize size=[消息大小:label.font];
CGFloat width=size.width+kPADDING;
label.frame=CGRectMake(xPos,0.0,宽度,self.frame.size.height);
[自添加子视图:标签];
xPos+=宽度;
}
self.messagesWidth=xPos;
self.contentSize=CGSizeMake(xPos,self.frame.size.height);
self.contentOffset=CGPointMake(-self.frame.size.width,0.0);
}
-(void)setMessages:(NSMutableArray*)消息{
如果(_messages!=消息){
_消息=消息;
[自建子视图];
}
}
-(无效)开始{
如果(!self.period)self.period=self.messagesWidth/100;
//因此,滚动整个数组所需的时间通常是相同的(捏造的,但合理的)
[UIView animateWithDuration:self.period
延迟:0.0
选项:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionRepeat
动画:^{
self.contentOffset=CGPointMake(self.messagesWidth,0.0);
}完成:^(BOOL finished){}];
}
@结束

您是指可以通过从右向左缓慢滚动显示宽度大于视图显示宽度的字符串集合的视图吗?你需要建造它。我曾经这样做过,通过如下子类化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
//CrawlView.h
#进口
@界面爬网视图:UIScrollView
@属性(赋值,非原子)NSTimeInterval期间;
@属性(强、非原子)NSMutableArray*消息;
-(无效)去;
@结束
//crawview.m
#导入“CrawlView.h”
//相邻字符串之间的距离。可以让这成为公共财产吗
#定义kp16.0
@界面爬网视图()
@属性(赋值,非原子)CGFloat messagesWidth;
@结束
@实现爬网视图
@合成周期=_周期;
@合成消息=_消息;
@合成messagesWidth=\u messagesWidth;
-(void)构建子视图{
对于(UIView*子视图在[自子视图]中){
if([subview iskindof类:[UILabel self]]){
[子视图从SuperView移除];
}
}
CGFloat xPos=kpos;
for(self.messages中的NSString*消息){
UILabel*label=[[UILabel alloc]initWithFrame:CGRectZero];
label.text=消息;
CGSize size=[消息大小:label.font];
CGFloat width=size.width+kPADDING;
label.frame=CGRectMake(xPos,0.0,宽度,self.frame.size.height);
[自添加子视图:标签];
xPos+=宽度;
}
self.messagesWidth=xPos;
self.contentSize=CGSizeMake(xPos,self.frame.size.height);
self.contentOffset=CGPointMake(-self.frame.size.width,0.0);
}
-(void)setMessages:(NSMutableArray*)消息{
如果(_messages!=消息){
_消息=消息;
[自建子视图];
}
}
-(无效)开始{
如果(!self.period)self.period=self.messagesWidth/100;
//因此,滚动整个数组所需的时间通常是相同的(捏造的,但合理的)
[UIView animateWithDuration:self.period
延迟:0.0
选项:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionRepeat
动画:^{
self.contentOffset=CGPointMake(self.messagesWidth,0.0);
}完成:^(BOOL finished){}];
}
@结束

两件事:你的问题不清楚,你尝试了什么?我正在尝试动态创建uiview,并将uiview像html字幕标记一样水平移动一次,而不重复动态uiview。。。!你是说你要创建多个视图?视图中会出现什么?是的,我正在尝试像游戏一样单击“动态uiview”隐藏在点上,并通过水平移动重新生成动态uiview。。!两件事:你的问题不清楚,你尝试过什么?我正在尝试动态创建uiview,并像html字幕标记一样将uiview水平移动一次,而不重复动态uiview。。。!你是说你要创建多个视图?视图中会出现什么?是的,我正在尝试像游戏一样单击“动态uiview”隐藏在点上,并通过水平移动重新生成动态uiview。。!如何使用此功能。。。!,它在这一行显示错误-@属性(强,非原子)NSMUTABLEARRY*消息;错误消息是未知属性strong,它的目标是iOS SDK 5.1(使用ARC)。你能为OS5构建吗?如果没有,您可以通过将“保留”更改为“保留”来了解它的工作原理,但不要以这种方式发送。除非你做额外的工作,否则它会泄漏内存