codebot codebot - 1 year ago 76
iOS Question

How to change frame rect when received a notification from NSNotificationCenter?

I have a view with a button to take an image from camera. When I press the capture button it'll redirect to another view controller. Once I take a photo, the view is pop to the previous view controller. When popping the view I also send a notification to the 1st view controller with the taken image. When the image is receive I tried to change the frame of view

method. But the frame didn't get update. What I tried was,

- (void) onReceiveImage:(NSNotification *) notification{
if ([[notification name] isEqualToString:@"ImageCapturedNotification"]) {
[self.postTxtView resignFirstResponder];
NSDictionary* userInfo = notification.userInfo;
UIImage *image = (UIImage*)userInfo[@"image"];
[self.postLandImageView setImage:image];
// in here i want to change the view frame

To change the frame I did,

self.bottomView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-self.bottomView.frame.size.width, self.view.bounds.size.height-self.bottomView.frame.size.height, self.bottomView.frame.size.width, self.bottomView.frame.size.height);

This is not working. Please help me tho get this done. Thanks.

Answer Source

Please check if you are executing your code on main thread.

For the most part, use UIKit classes only from your app’s main thread. This is particularly true for classes derived from UIResponder or that involve manipulating your app’s user interface in any way.

    dispatch_async(dispatch_get_main_queue(), ^{
        // Do any setup on main queue

If you are excuting your code on main thread,can you provide a sample demo?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download