iPhone SDK: 图像捕捉横屏模式

5

我希望我的用户可以在横屏模式下在屏幕上绘制一张图片。

在按下按钮后,该图像应存储在设备上的本地位置。

我正在使用下面这个代码示例,它在垂直方向上工作http://www.ipodtouchfans.com/forums/showthread.php?t=132024

我的问题是,我正在尝试调整代码以适应较小的绘画区域,但它不起作用。我不确定为什么?

似乎有三个涉及用户可绘制范围的区域。我已经尝试更改大小,但似乎不起作用。我错过了什么吗?

Orignally:

viewDidLoad:
drawImage = [[UIImageView alloc] initWithImage:nil];
drawImage.frame = self.view.frame;

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UIGraphicsBeginImageContext(self.view.frame.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
...
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

UIGraphicsBeginImageContext(self.view.frame.size);
        [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
...
}

1
不太清楚您的问题。您是遇到了在屏幕上绘图的麻烦,还是在捕获图像并存储它的过程中遇到了困难? 您的代码出现了什么问题?也就是说:(a)您期望发生什么?(b)相反,发生了什么事情? - Olie
你能展示一下你用来调整横屏模式下较小绘图区域的代码部分吗?也许你没有做对。 - fulvio
"drawImage.frame = self.view.frame;" -> 你确定这是你想要做的吗?通常你应该设置子视图的frame为self.view.bounds。 - Geoffroy
2个回答

0
如果您只想使用横向视图,请将以下代码添加到示例中:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        return YES;
    else 
        return NO;
}

并且进入项目属性,将设备方向设置为左横屏右横屏

希望这能解决你的问题。


-1

我也在使用那段代码进行绘图,当我切换到横屏模式时,我会再次为我们的drawimage或您用于绘图的视图提供框架。如果您从xib类中提供了UIView类,则最好从那里设置横向模式框架。

是的,如果在纵向模式下进行一些绘图并切换到横向模式,则必须根据您的区域调整其lastpoint和currentpoints。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接