• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - F3PlotStrip 动态添加图有问题

[复制链接]
菜鸟教程小白 发表于 2022-12-12 10:02:50 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我目前正在开发基于 Graphs 的 iOS 应用程序。为此,我使用了一个名为 F3PlotStrip 的第三方控件。 .

实现类似于:

- (void)viewDidLoad
{
    _ecgView = [[F3PlotStrip alloc] initWithFrame:CGRectMake(50, 50, 648, 299)];
    _ecgView.lineColor = [UIColor greenColor];
    _ecgView.lowerLimit = -10.0f;
    _ecgView.upperLimit = 10.0f;
    [self.view addSubview:_ecgView];
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selectorselector(testGraph userInfo:nil repeats:YES];
}

- (void)testGraphNSTimer *)a_timer
{
    _ecgView.value = 1.0;
}

但我得到的结果如下:

Code F3

然后我在 xib 中添加了一个 UIView 并将其类更改为 F3PlotStrip 然后将其作为 _ecgView< 连接到 socket

然后我将代码更改为:

- (void)viewDidLoad
{
    _ecgView.lineColor = [UIColor greenColor];
    _ecgView.lowerLimit = -10.0f;
    _ecgView.upperLimit = 10.0f;
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selectorselector(testGraph userInfo:nil repeats:YES];
}

- (void)testGraphNSTimer *)a_timer
{
    _ecgView.value = 1.0;
}

这一次,我得到了实际的输出:

IB F3

但是为什么当我通过代码添加 View 时会出现问题?我不能依赖第二种方法(通过 IB),因为我需要动态添加图表。有没有办法解决这个问题?还是这是 F3PlotStrip 的 bug?



Best Answer-推荐答案


我今天早上开始使用这个小部件。我现在在 iPhone 上躺在床上,所以无法发布我想发布的内容,但我会在早上上类时发布。

我已经设法使用它并通过动态添加的 UIView(或者我应该说 F3PlotStrip)执行您想要执行的操作。

我还制作了 .h 和 .m,也符合 ARC。不确定你是否这样做了。

我将在明天完成一些不错的代码,这些代码使用 NSTimer 读取 NSArray 的内容以动态绘制,并带有动画。再次使用我作为 subview 添加到我的 View Controller 的 View 。

没有详细查看您的代码,因为我明天已经设法开始工作了。

好的 - 我在工作,坐在 Xcode 前面。这是我用作此小部件的基本测试平台的 VC。昨晚我很快就把它敲了起来,但完成了工作。最初,我在我的 Storyboard 第一个 VC 中添加了一个 UIView,并将其子类化为 F3PlotStrip。但是,鉴于我看到您在动态添加 UIView 时遇到问题,我想我会试一试。你和我的唯一区别是我在 alloc-init 之后设置 UIView 的框架。看你怎么想。它使用 Sparkline 方法以及在屏幕上以动画形式显示图表。

//
//  PlotViewController.m
//  PlotTest
//
//  Created by Carl Hine on 16/05/2013.
//  Copyright (c) 2013 Carl Hine. All rights reserved.
//

#define COLOUR_POWDER_BLUE                  [[UIColor alloc] initWithRed:176/255.0f     green:224/255.0f blue:230/255.0f alpha:1]

#import "F3PlotStrip.h"
#import "lotViewController.h"

@interface PlotViewController ()

@property (strong, nonatomic) IBOutlet F3PlotStrip *IBOPLotView;
@property (strong, nonatomic) NSTimer *plotStipTimer;
@property (strong, nonatomic) NSArray *plotData;
@property (nonatomic) NSInteger plotDataArrayIdx;
@property (strong, nonatomic) F3PlotStrip *plotView2;

@end

@implementation PlotViewController

@synthesize plotStipTimer;
@synthesize plotData;
@synthesize plotDataArrayIdx;

BOOL bUsingDynPlot = YES;

- (id)initWithNibNameNSString *)nibNameOrNil bundleNSBundle *)nibBundleOrNil {

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)testGraphNSTimer *)a_timer {

    float RSEFigure = [[self.plotData objectAtIndex:plotDataArrayIdx] floatValue];

    if (bUsingDynPlot)
        _plotView2.value = RSEFigure;
    else
        _IBOPLotView.value = RSEFigure;

    ++plotDataArrayIdx;

    if (plotDataArrayIdx == [self.plotData count]) {
        [plotStipTimer invalidate];
        plotStipTimer = nil;
    }

}

- (void)configurePLotStripF3PlotStrip *)plotStrip {

    plotDataArrayIdx = 0;
    // Random rubbish that makes it look like a heartbeat :
    self.plotData = [NSArray arrayWithObjects:[NSNumber numberWithFloat:68.1f],
                 [NSNumber numberWithFloat:70.2f],
                 [NSNumber numberWithFloat:71.3f],
                 [NSNumber numberWithFloat:72.4f],
                 [NSNumber numberWithFloat:73.5f],
                 [NSNumber numberWithFloat:73.5f],
                 [NSNumber numberWithFloat:100.5f],
                 [NSNumber numberWithFloat:124.5f],
                 [NSNumber numberWithFloat:10.5f],
                 [NSNumber numberWithFloat:73.5f],
                 [NSNumber numberWithFloat:70.6f],
                 [NSNumber numberWithFloat:70.2f],
                 [NSNumber numberWithFloat:71.3f],
                 [NSNumber numberWithFloat:72.4f],
                 [NSNumber numberWithFloat:73.5f],
                 [NSNumber numberWithFloat:73.5f],
                 [NSNumber numberWithFloat:100.5f],
                 [NSNumber numberWithFloat:124.5f],
                 [NSNumber numberWithFloat:10.5f],
                 [NSNumber numberWithFloat:73.5f],
                 [NSNumber numberWithFloat:70.6f],
                 [NSNumber numberWithFloat:70.2f],
                 [NSNumber numberWithFloat:71.3f],
                 [NSNumber numberWithFloat:72.4f],
                 [NSNumber numberWithFloat:73.5f],
                 [NSNumber numberWithFloat:73.5f],
                 [NSNumber numberWithFloat:100.5f],
                 [NSNumber numberWithFloat:124.5f],
                 [NSNumber numberWithFloat:10.5f],
                 [NSNumber numberWithFloat:73.5f],
                 [NSNumber numberWithFloat:70.6f],
                 nil];

    // Get value bounds
    float max = -999999;
    float min = 999999;
    for (NSInteger i = 0;i <= self.plotData.count - 1;++i) {
        float RSEFigure = [[self.plotData objectAtIndex:i] floatValue];
        if (RSEFigure > max)
            max = RSEFigure;
        if (RSEFigure < min)
            min = RSEFigure;
    }

    plotStrip.lowerLimit = min;
    plotStrip.upperLimit = max;
    plotStrip.lineColor = COLOUR_POWDER_BLUE;
    [self.view addSubview:_IBOPLotView];
    plotStipTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selectorselector(testGraph userInfo:nil repeats:YES];
    plotStrip.showDot = YES;
    plotStrip.capacity = self.plotData.count;

}

- (void)viewDidLoad {

    if (bUsingDynPlot) {
        // Dynamically adding to view.
        _plotView2 = [[F3PlotStrip alloc] init];
        _plotView2.backgroundColor = [UIColor redColor];
        _plotView2.frame = CGRectMake(0, 100, 293, 35);
        [[self view] addSubview:_plotView2];
        [self configurePLotStrip:_plotView2];
    } else {
        [self configurePLotStrip:_IBOPLotView];
    }
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}

@end

我希望这很容易让您加入新的 VC。如果您的项目文件夹中有 F3PlotStrip.h 和 .m,那么您就可以使用了 - 除了将 UIView 添加到 VC 之外。

卡尔。

关于ios - F3PlotStrip 动态添加图有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15780266/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap