Tuesday 15 January 2013

iphone - CAGradientLayer - Doesn't cover the view completely in landscape orientation -


I used to create a gradient background for my app. It is very beautiful. However, when I change orientation, then there is a problem.

It seems appropriate in portrait mode, but the gradient in the landscape orientation does not cover the whole scene. I uploaded a screenshot -

http://www.screencast.com/t/ C4vUv55Xq0

There is a red shield and the blue part is the default background color which is to be completely covered with red gradient.

How can I cover the entire scene? I tried to call the method of gradient after detecting the rotation change but it does not work. This is the code I used:

  [[NSNotificationCenter defaultCenter] addObserver: Self Selector: @Sillector (DeviceInternationalDid Change Notification :) Name: UIDeviceOrientationDidChangeNotification Object: Zero]; // This is in the 'viewWillAppear' method - (empty) Device OperationDead Change Notification: (NSNitification *) Note {UIDIVIS Orientation Orientation = [[UIDEWIS current device] Orientation]; [Self adbackground]; }   

My guess sends to system system UIDeviceOrientationDidChangeNotification Updating the visual hierarchy for the first landscape layout. Instead of reducing the gradient in response to

UIDeviceOrientationDidChangeNotification , do it in viewDidLayoutSubviews . When your View Controller receives viewDidLayoutSubviews , the frame of the view has already been modified for the new interface orientation. Something like this should be done: - (zero) viewDidleLiveSubview {{Super ViewedLightSubes view}; Self.background.frame = self.view.bounds; }

No comments:

Post a Comment