ios - Is it possible to move a ui element from one location to the other using fading? -
i able fade out uiview location , fade in @ location b at same time. possible ios?
one way create image of view, put on screen (in image view) on actual view, set view's alpha 0, set frame (or adjust layout constraints) put in new position, start animation fades out image, , fades in actual view.
something should work:
#import "viewcontroller.h" #import <quartzcore/quartzcore.h> @interface viewcontroller () @property (weak,nonatomic) iboutlet uiview *fadingview; @property (weak,nonatomic) iboutlet nslayoutconstraint *topcon; @property (strong,nonatomic) uiimageview *iv; @end @implementation viewcontroller -(ibaction)moveview:(id)sender { uiimage *viewimage = [self imagewithview:self.fadingview]; self.iv = [[uiimageview alloc] initwithframe:self.fadingview.frame]; self.iv.image = viewimage; [self.view addsubview:self.iv]; self.fadingview.alpha = 0; self.topcon.constant = 200; // topcon iboutlet top constraint superview [uiview animatewithduration:1 animations:^{ self.fadingview.alpha = 1; self.iv.alpha = 0; } completion:^(bool finished) { [self.iv removefromsuperview]; }]; } - (uiimage *)imagewithview:(uiview *)view { uigraphicsbeginimagecontextwithoptions(cgsizemake(view.bounds.size.width, view.bounds.size.height), view.opaque, [[uiscreen mainscreen] scale]); [view.layer renderincontext:uigraphicsgetcurrentcontext()]; uiimage * img = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return img; }
Comments
Post a Comment