iphone - How to dimiss a UIAlertView when tapping anywhere on the window -
i opening alert popup on click button working fine code is
uialertview *alert = [[uialertview alloc] initwithtitle:@"popup title" message:@"this pop window/ alert" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; uiimageview *tempimageview=[[uiimageview alloc]initwithframe:cgrectmake(20,20,50,50)]; tempimageview.image=[uiimage imagenamed:@"abc.png"]; [alert addsubview:tempimageview] [alert show];
the alert box closing on click of ok button ,i don't want it, wants colse alert box on click of on window . please me.
it sounds trying recreate "toast" on ios. news, has done that. see project.
edit: don't want use itoast. style, less code is. here come with. seem obvious others have said way overcome modal nature of uialertview
add superview handle touch events. don't have manually every time, consider subclassing uialertview
. try this:
edit: @wagashi, accepting answer, , heads setframe:
being place adjust size. code make toast-like little alert, when tried found if message long view seemed fall apart. have modified setframe:
reduce size of alert size of 1 button, , remain centered on screen. class accurately answers question title "ios how dismiss uialertview 1 tap anywhere?"
nobuttonalertview.h
#import <uikit/uikit.h> @interface _nobuttonalertviewcover : uiview @property (nonatomic,assign) uialertview *delegate; @end @interface nobuttonalertview : uialertview -(id)initwithtitle:(nsstring *)title message:(nsstring *)message; @end
nobuttonalertview.m
#import "nobuttonalertview.h" @implementation _nobuttonalertviewcover @synthesize delegate = _delegate; -(void)touchesended:(nsset *)touches withevent:(uievent *)event{ [self removefromsuperview]; [_delegate dismisswithclickedbuttonindex:0 animated:yes]; } @end @implementation nobuttonalertview -(void)show{ [super show]; _nobuttonalertviewcover *cover = [[_nobuttonalertviewcover alloc] initwithframe:[uiscreen mainscreen].bounds]; cover.userinteractionenabled = yes; cover.backgroundcolor = [[uicolor lightgraycolor] colorwithalphacomponent:.01]; cover.delegate = self; [self.superview addsubview:cover]; } -(id)initwithtitle:(nsstring *)title message:(nsstring *)message{ if ((self = [super initwithtitle:title message:message delegate:nil cancelbuttontitle:nil otherbuttontitles:nil, nil])){ } return self; } - (void)setframe:(cgrect)rect { // called multiple times, 4 of times count, reduce height 40 rect.size.height -= 10; self.center = self.superview.center; [super setframe:rect]; } @end
with simple uialertview
subclass , uiview
subclass cover, can use standard uialertview
. so:
nobuttonalertview *alert = [[nobuttonalertview alloc] initwithtitle:@"hello" message:@"i model of modern major general; i'm information, vegitable, animal, , mineral."]; [alert show];
will yield:
Comments
Post a Comment