【发布时间】:2012-03-22 12:27:06
【问题描述】:
所以我正在尝试绘制一些网格线,这些网格线在横向一直到底部,但是当我切换到横向时,图形不跟随并且网格线变小。
我已经设置了
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
但它仍然不起作用,这是我的代码。谁能发现问题?这是自定义视图文件,除了上面返回yes的代码之外,视图控制器是默认的。
.h file
#import <UIKit/UIKit.h>
#define kGraphHeight 300
#define kDefaultGraphWidth 900
#define kOffsetX 10
#define kStepX 50
#define kGraphBottom 300
#define kGraphTop 0
@interface GraphView : UIView
@end
这是实现
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 0.6);
CGContextSetStrokeColorWithColor(context, [[UIColor lightGrayColor] CGColor]);
// How many lines?
int howMany = (kDefaultGraphWidth - kOffsetX) / kStepX;
// Here the lines go
for (int i = 0; i < howMany; i++)
{
CGContextMoveToPoint(context, kOffsetX + i * kStepX, kGraphTop);
CGContextAddLineToPoint(context, kOffsetX + i * kStepX, kGraphBottom);
}
CGContextStrokePath(context);
}
任何帮助将不胜感激
顺便说一句,我正在关注本教程
http://buildmobile.com/creating-a-graph-with-quartz-2d/#fbid=YDPLqDHZ_9X
【问题讨论】:
标签: objective-c iphone xcode cocos2d-iphone