objective c - iOS - Custom Confirmation view -
i working on creating custom control once user presses button , action completes. i'm trying replicate behavior of apple music app when album added shows confirmation view in center check mark shown below. there similar cocoa controls available use?
(swift) create singleton class
class customview: uiview {
class var sharedview : customview { struct static { static var instance : customview? static var token : dispatch_once_t = 0 } dispatch_once(&static.token) { static.instance = customview() } return static.instance! } override init(frame: cgrect) { super.init(frame: frame) } required init(coder adecoder: nscoder) { super.init(coder: adecoder) } func showinview(view:uiwindow) { var image = uiimage(named:"someimage") self.frame = view.frame var originx = view.center.x var originy = view.center.y let centerview = uiimageview() centerview.center = cgpointmake(originx, originy) centerview.contentmode = uiviewcontentmode.center centerview.image = image centerview.alpha = 0 self.addsubview(centerview) view.addsubview(self) uiview.animatewithduration(1, animations: { () -> void in centerview.alpha = 1 }) { (_) -> void in uiview.animatewithduration(1, animations: { () -> void in centerview.frame.size = cgsizemake(0,0) centerview.alpha = 0 }) { (_) -> void in self.hide() } } } func hide() { if self.superview != nil { self.removefromsuperview() } }
}
in viewcontroller can call method customview.sharedview.showinview(view:uiapplication.sharedapplication.keywindow())
objective c .h
#import <uikit/uikit.h> @interface customview : uiview + (instancetype)sharedinstance; -(void)showinview:(uiwindow*)view; @end
objective c .m
#import "customview.h" @implementation customview + (instancetype)sharedinstance { static customview *sharedinstance = nil; static dispatch_once_t oncetoken; dispatch_once(&oncetoken, ^{ sharedinstance = [[customview alloc] init]; }); return sharedinstance; } - (instancetype)initwithcoder:(nscoder *)coder { self = [super initwithcoder:coder]; if (self) { } return self; } - (instancetype)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { } return self; } -(void)showinview:(uiwindow*)view { uiimage *image = [uiimage imagenamed:@"img.png"]; self.frame = view.frame; cgfloat originx = view.center.x; cgfloat originy = view.center.y; uiimageview *centerview = [uiimageview new]; centerview.center = cgpointmake(originx, originy); centerview.contentmode = uiviewcontentmodecenter; centerview.image = image; centerview.alpha = 0; [self addsubview:centerview]; [view addsubview:self]; [uiview animatewithduration:1 animations:^{ centerview.alpha = 1; } completion:^(bool finished) { [uiview animatewithduration:1 animations:^{ centerview.frame = cgrectmake(originx, originy, 0, 0); centerview.alpha = 0; } completion:^(bool finished) { [self hideview]; }]; }]; } -(void)hideview { if(self.superview) { [self removefromsuperview]; } } @end
import customview.h in file ,
[[customview sharedinstance] showinview:[[uiapplication sharedapplication]keywindow]];
Comments
Post a Comment