i have uiviewcontroller has image view , toolbar. toolbar rotate, imageview stay is. possible?
yes possible, requires manual handling of rotate events.
in viewdidload, add
// store current orientation currentorientation = uiinterfaceorientationportrait; [[uidevice currentdevice] begingeneratingdeviceorientationnotifications]; [[nsnotificationcenter defaultcenter] addobserver:self selector: @selector(receivedrotate:) name: uideviceorientationdidchangenotification object: nil]; if(currentorientation != self.interfaceorientation) { [self deviceinterfaceorientationchanged:self.interfaceorientation]; }
and don't forget deregister events when controller removed. add method rotates:
// method called nsnotificationcenter when device rotated. -(void) receivedrotate: (nsnotification*) notification { nslog(@"receivedrotate"); uideviceorientation interfaceorientation = [[uidevice currentdevice] orientation]; if(interfaceorientation != uideviceorientationunknown) { [self deviceinterfaceorientationchanged:interfaceorientation]; } else { nslog(@"unknown device orientation"); } }
and rotate method
- (void)deviceinterfaceorientationchanged:(uiinterfaceorientation)interfaceorientation { if(interfaceorientation == currentorientation) { nslog(@"do not rotate current orientation: %i", interfaceorientation); } else if(interfaceorientation == uiinterfaceorientationportraitupsidedown) { nslog(@"do not rotate uiinterfaceorientationportraitupsidedown"); } else if(interfaceorientation == uiinterfaceorientationlandscapeleft) { nslog(@"do not rotate uiinterfaceorientationlandscapeleft"); } else { if(!isrotating) { isrotating = yes; if(currentorientation == uiinterfaceorientationportrait && interfaceorientation == uiinterfaceorientationlandscaperight) { nslog(@"rotate landscape"); // rotate right top corner [uiview beginanimations:nil context:null]; [uiview setanimationduration:0.5]; // rotation here [uiview setanimationdelegate:self]; [uiview setanimationdidstopselector:@selector(animationdoneshowcaption:finished:context:)]; [uiview commitanimations]; } else if(currentorientation == uiinterfaceorientationlandscaperight && interfaceorientation == uiinterfaceorientationportrait) { // etc } isrotating = no; } else { nslog(@"we rotating.."); } } currentorientation = interfaceorientation; }
note not allow rotates in directions, might.
in addition, need make components resizable / able rotate.
edit consider using block-based animations instead , set isrotation = no in completion block.
Comments
Post a Comment