ios - Center UIView in center of MainScreen Despite Location of Superview -
i have uiview can dragged around. in uiview have subview want centered on device screen both height , width. ever try centers superview. how can make subview @ center of uidevice mainscreen despite uiview is.
i have (stripped down because 50000 lines long):
popartwork = [uiimageview new]; popartwork.frame = cgrectmake(367, 367, widgetwidth, widgetwidth/5.3); popartwork.layer.cornerradius = 10; popartwork.layer.maskstobounds = yes; popartwork.alpha = 0; [popartwork setuserinteractionenabled:yes]; [add addsubview:popartwork];
add superview. program little unusual in way music widget user's home screen (jailbreak tweak) can move ever. want view popartwork in center of screen despite wherever add might be.
i don't know if it's looking for, how center subview when superview re-positioned:
- (void)viewdidload { [super viewdidload]; uipangesturerecognizer *pan = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(paned:)]; [_add addgesturerecognizer:pan]; } -(void)paned:(uipangesturerecognizer *)pan{ cgpoint translatedpoint = [(uipangesturerecognizer*)pan translationinview:self.view]; if ([(uipangesturerecognizer*)pan state] == uigesturerecognizerstatebegan) { firstx = [[pan view] center].x; firsty = [[pan view] center].y; } translatedpoint = cgpointmake(firstx+translatedpoint.x, firsty+translatedpoint.y); [[pan view] setcenter:translatedpoint]; cgrect newsubviewframe = _subview.frame; newsubviewframe.origin.x = [uiscreen mainscreen].bounds.size.width/2.0 - newsubviewframe.size.width/2.0 - _add.frame.origin.x; newsubviewframe.origin.y = [uiscreen mainscreen].bounds.size.height/2.0 - newsubviewframe.size.height/2.0 - _add.frame.origin.y; _subview.frame = newsubviewframe; }
Comments
Post a Comment