Ios 在Objective-C中绘图
我知道您可以使用CoreGraphics在视图中绘制。但它仅限于drawRect函数 我想知道你是否可以有一个应用程序,它有两个按钮(上、下、左、右)。当用户选择按钮时,它会在按钮方向上从原点画一条线,这个方向刚刚被选择了20个像素 例如: 假设用户点击右键:Ios 在Objective-C中绘图,ios,objective-c,Ios,Objective C,我知道您可以使用CoreGraphics在视图中绘制。但它仅限于drawRect函数 我想知道你是否可以有一个应用程序,它有两个按钮(上、下、左、右)。当用户选择按钮时,它会在按钮方向上从原点画一条线,这个方向刚刚被选择了20个像素 例如: 假设用户点击右键: Start +----------+ Start +----------+
Start
+----------+
Start
+----------+
|
|
|
|
+
然后他们按下向下按钮:
Start
+----------+
Start
+----------+
|
|
|
|
+
然后他们按左键
+----------+
|
|
|
|
+----------+
等等,
这可以使用quartz完成吗?或者我需要学习类似OpenGL的东西吗?使用
UIBezierPath
非常简单:
这是一个快速的,基本的例子如何绘制它
MoveView
,使用公共方法-moveToDirection:
-setNeedsDisplay
来绘制新线#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, MovieViewDirection) {
MoveViewDirectionRight,
MoveViewDirectionLeft,
MoveViewDirectionUp,
MoveViewDirectionDown
};
@interface MoveView : UIView
- (void)moveInDirection:(MovieViewDirection)direction;
@end
这就是我得到的:
使用
UIBezierPath
非常简单:
这是一个快速的,基本的例子如何绘制它
MoveView
,使用公共方法-moveToDirection:
-setNeedsDisplay
来绘制新线#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, MovieViewDirection) {
MoveViewDirectionRight,
MoveViewDirectionLeft,
MoveViewDirectionUp,
MoveViewDirectionDown
};
@interface MoveView : UIView
- (void)moveInDirection:(MovieViewDirection)direction;
@end
这就是我得到的:
使用
UIBezierPath
非常简单:
这是一个快速的,基本的例子如何绘制它
MoveView
,使用公共方法-moveToDirection:
-setNeedsDisplay
来绘制新线#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, MovieViewDirection) {
MoveViewDirectionRight,
MoveViewDirectionLeft,
MoveViewDirectionUp,
MoveViewDirectionDown
};
@interface MoveView : UIView
- (void)moveInDirection:(MovieViewDirection)direction;
@end
这就是我得到的:
使用
UIBezierPath
非常简单:
这是一个快速的,基本的例子如何绘制它
MoveView
,使用公共方法-moveToDirection:
-setNeedsDisplay
来绘制新线#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, MovieViewDirection) {
MoveViewDirectionRight,
MoveViewDirectionLeft,
MoveViewDirectionUp,
MoveViewDirectionDown
};
@interface MoveView : UIView
- (void)moveInDirection:(MovieViewDirection)direction;
@end
这就是我得到的:
您可以使用UIBezier路径。为什么不在
-drawRect:
中执行?您可以使用UIBezier路径。为什么不在-drawRect:
中执行?您可以使用UIBezier路径。为什么不在-drawRect:
中执行?您可以使用UIBezier路径。为什么不在-drawRect:
中执行?