【问题标题】:How to remove view and redraw it如何删除视图并重绘它
【发布时间】:2011-06-06 18:40:25
【问题描述】:

我有一个可以绘制的视图。当用户单击取消按钮时,视图被清除并在该视图中绘制新图像。我正在发布我的代码。有人可以帮忙吗?

#import "SignatureViewController.h"


@implementation SignatureViewController
@synthesize salesToolBar;



-(void)buttonpressed
{
    NSString *allElements = [myarray componentsJoinedByString:@""];
    NSLog(@"%@", allElements);}


-(void)buttonclear{

        [drawImage removeFromSuperview];

    //UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.height, self.view.frame.size.width));       
     drawImage = [[UIImageView alloc] initWithImage:nil];
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width )];
    drawImage.frame = self.view.frame;
   [self.view addSubview:drawImage];
    self.view.backgroundColor = [UIColor greenColor];
    mouseMoved = 0;
        //[super viewDidLoad];

}

-(void)buttoncancel{
    [[self navigationController] popViewControllerAnimated: YES];
     [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;

}


- (void)viewDidLoad {
    [super viewDidLoad];
    myarray = [[NSMutableArray alloc] init];


    CGFloat x = self.view.bounds.size.width / 2.0;
    CGFloat y = self.view.bounds.size.height / 2.0;
    CGPoint center = CGPointMake(y, x);

    // set the new center point
    self.view.center = center;

    CGAffineTransform transform = self.view.transform;
        transform = CGAffineTransformRotate(transform, -(M_PI / 2.0));

    self.view.transform = transform;

    self.view.backgroundColor = [UIColor greenColor];
    self.title = @"Signature";

    [self createToolbar];

    NSLog(@"View Did Load Run");


}

- (void)viewDidAppear:(BOOL)animated {
    NSLog(@"Self.view.frame.height = %f and width = %f ", self.view.frame.size.height, self.view.frame.size.width);
    NSLog(@"View Did Appear Run");
    self.navigationController.navigationBarHidden=TRUE;
    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;



    [super viewDidLoad];

}

【问题讨论】:

  • 您能更准确地了解您的需求吗?这个新图像如何可用?现在看来nil。您正在向其发送drawInRect: 消息。此代码还有一些错误。

标签: iphone cocoa-touch


【解决方案1】:

听起来您需要在视图上调用 setNeedsDisplay:。 :)

【讨论】:

  • 嗯,图像是在视图上绘制的图像。我的图像视图称为 drawimage。我正在发布整个代码。我想我修复了所有问题,除了取消按钮。
  • 是的,所以尝试在包含图像视图的视图上调用以下命令... [self.view setNeedsDisplay];
  • 我的视图没有被正确清除,所以在我尝试重绘图像时清除按钮后,我只看到屏幕的一部分,整个屏幕第一次可用。所以我需要帮助调整我的屏幕大小,以便在清除按钮后我得到全屏。
  • 所以当你说你只得到屏幕的一部分时——你的 NSLogs 对 self.frame.size.height 和 width 有什么看法?此外,在 buttonClear 中,我可以看到 drawImage 在哪里分配 - 我认为这应该在 viewDidLoad 中......假设它应该已经存在,并且每次按下清除按钮时都不会继续创建和删除它?
  • 是的,它是真的......我有点困惑如何清除我的视图并重新绘制它......我是 xcode 的新手
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-15
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多