更改背景圖片我已經點擊手勢設置和它,當我點擊它在模擬器中的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?
嘗試在'viewDidLoad'中設置'backgroundColor'並查看它是否有效 – kezi
通常,您不需要再調用任何東西。但嘗試setNeedDisplay。或嘗試不同的圖像? – anhtu
嘗試強制進入主線程(即):dispatch_async(dispatch_get_main_queue(),^ {[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@「table-2」]]]; }}); ' – Oxcug