iPhone SDK:图像捕捉横向模式

时间:2010-09-10 18:55:28

标签: iphone

我想让我的用户以横向模式在他们的屏幕上绘制图片。

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

我正在使用下面的代码示例,它垂直工作 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)];
...
}

2 个答案:

答案 0 :(得分:0)

如果您打算只有横向视图。然后将以下代码添加到示例中: -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        return YES;
    else 
        return NO;
}

转到项目属性并将设备方向设置为左侧风景风景右侧

希望这能解决您的问题。

答案 1 :(得分:-1)

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

是的,如果在纵向模式下绘制并切换到横向模式,则必须根据您的区域调整其最后一点和当前点。