UIButton Add in window, click No effect, look for a long time, originally was not added this: [Self.window makekeyandvisible];
Self.window =[[UIWindow alloc]initwithframe:[[uiscreen mainscreen] bounds]; Viewcontroller*VC =[[Viewcontroller alloc] init]; Self.window.rootViewController=VC; Self.window.backgroundColor=[Uicolor Whitecolor]; [Self.window makekeyandvisible]; View1= [[UIView alloc] Initwithframe:cgrectmake ( -, $, $, -)]; View1.backgroundcolor=[Uicolor Bluecolor]; [Self.window Addsubview:view1]; UIView*view2 = [[UIView alloc] Initwithframe:cgrectmake ( -, $, -, Max)]; View2.backgroundcolor=[Uicolor Yellowcolor]; [Self.window Addsubview:view2]; UIView*VIEW3 = [[UIView alloc] Initwithframe:cgrectmake ( -, -, $, -)]; View3.backgroundcolor=[Uicolor Redcolor]; [Self.window ADDSUBVIEW:VIEW3]; UIButton*button =[UIButton Buttonwithtype:uibuttontyperoundedrect]; Button.frame= CGRectMake ( -,510, -, *); Button.userinteractionenabled=YES; Button.backgroundcolor=[Uicolor Greencolor]; [Button Settitle:@" Change"Forstate:uicontrolstatenormal]; [Button addtarget:self action: @selector (ChangeView) forcontrolevents:uicontroleventtouchupinside]; [Self.window Addsubview:button]; NSLog (@"%@", self.window.subviews);
-(void) changeview{ [Self.window bringsubviewtofront:view1]; NSLog (@ "%@", Self.window.subviews);}
Do not add directly to the window, add the Viewcontroller viewdidload click on the effect
View1 = [[UIView alloc] Initwithframe:cgrectmake ( -, $, $, -)]; View1.backgroundcolor=[Uicolor Bluecolor]; [Self.view Addsubview:view1]; UIView*view2 = [[UIView alloc] Initwithframe:cgrectmake ( -, $, -, Max)]; View2.backgroundcolor=[Uicolor Yellowcolor]; View2.tag=2; [Self.view Addsubview:view2]; UIView*VIEW3 = [[UIView alloc] Initwithframe:cgrectmake ( -, -, $, -)]; View3.backgroundcolor=[Uicolor Redcolor]; [Self.view ADDSUBVIEW:VIEW3]; UIButton*button =[UIButton Buttonwithtype:uibuttontyperoundedrect]; Button.frame= CGRectMake ( -,510, -, *); Button.userinteractionenabled=YES; Button.backgroundcolor=[Uicolor Greencolor]; [Button Settitle:@" Change"Forstate:uicontrolstatenormal]; [Button addtarget:self action: @selector (ChangeView) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button]; NSLog (@"%@", self.view.subviews);
-(void) changeview{ [Self.view bringsubviewtofront:view1]; *view = [Self.view viewwithtag:2]; = [Uicolor purplecolor]; NSLog (@ "%@", Self.view.subviews);}
IOS UIButton Plus click on window for no effect problem