简体   繁体   中英

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 setFrame 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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM