2015-08-31 87 views
1

更改背景圖片我已經點擊手勢設置和它,當我點擊它在模擬器中的NSLog火災,所以我敢肯定,它擊中它:的iOS:自來水手勢

@implementation CoolController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    ... 

    UITapGestureRecognizer *backgroundTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTapped)]; 
    backgroundTapRecognizer.numberOfTapsRequired = 2; 
    [self.view addGestureRecognizer:backgroundTapRecognizer]; 
} 

- (void) backgroundTapped { 
    NSLog(@"cool"); // <-- this fires when I tap it twice 
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"table-2"]]]; 
} 

然而,背景中的圖像不會改變。我是否需要調用另一種方法來更新UI?

+0

嘗試在'viewDidLoad'中設置'backgroundColor'並查看它是否有效 – kezi

+0

通常,您不需要再調用任何東西。但嘗試setNeedDisplay。或嘗試不同的圖像? – anhtu

+0

嘗試強制進入主線程(即):dispatch_async(dispatch_get_main_queue(),^ {[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@「table-2」]]]; }}); ' – Oxcug

回答

0

嘗試此

  • (無效)backgroundTapped:(ID)發送方
0

在viewDidLoad中嘗試此和檢查顏色變化:

[self.view setBackgroundColor :[UIColor colorWithPatternImage:[UIImage imageNamed:@「table-2.png」]]];

無論它是什麼擴大您的圖像png/jpg。希望它有幫助