- UIViewController 中的方法应该能够识别滑块值何时发生变化
- 相同的方法应该触发 UIViewController 中的另一个方法来更新/重新计算正弦函数值(例如创建一个值数组)
- 在更新方法结束时,必要的值通过从 UIViewController 到 UIView 的出口传输到 UIView(UIView 是 UIViewController 的属性)
- UIView 正在绘制矩形中绘制新的正弦函数
编辑 1:您的 ViewController.h:
#import <UIKit/UIKit.h>
@class YourGraphUIView; // that's you view where you draw
@interface ResultViewController: UIViewController
@property (weak, nonatomic) IBOutlet UISlider *valueFromSlider; //bound to your UISlider
@property (weak) IBOutlet YourGraphUIView *yourGraphUIView; //bound to your costumUIView
@property (nonatomic, retain) NSNumber *graphValue;
- (IBAction)takeSliderValue:(id)sender; //bound to your UISlider
@end
你的 ViewController.m:
#import "ResultViewController.h"
#import "YourGraphUIView.h"
@interface ResultViewController ()
@end
@implementation ResultViewController
@synthesize yourGraphUIView, valueFromSlider, graphValue;
- (IBAction)takeSliderValue:(UISlider *)sender{
graphValue = [NSNumber numberWithDouble:[(double)sender.value]]; //takes value from UISlider
yourGraphUIView.graphValue = graphValue; //gives the value to the yourGraphUIView
[self.yourGraphUIView setNeedsDisplay] //<--- important to redraw UIView after changes
}
end
你的YourGraphUIView.h:
#import <UIKit/UIKit.h>
@interface YourGraphUIView : UIView
@property(nonatomic, retain)NSNumber *graphValue;
- (void)drawRect:(CGRect)dirtyRect;
@end
你的YourGraphUIView.m:
#import "YourGraphUIView.h"
@implementation YoutGraphUIView
@synthesize graphValue;
//... init, draw rect with using the graphValue for calculating and updating the graph
end;
我希望这会有所帮助。您应该看看如何构建 GUI 以及如何连接 UIView。您还需要为 ViewController 和 YourGraphUIView 设置自定义类。祝你好运!