1

所以我有一个视图寻呼机,它假设允许用户以用户期望在相册中滑动的方式滑动照片,但是当用户滑动并尝试按下“共享”按钮时,问题就出现了导航栏。如果用户只是从相册中打开一张照片并且从不尝试向右或向左滑动,则它工作正常,但如果他们确实尝试向任一方向滑动然后尝试保存他们已滑动到的照片,则在照片之后返回照片用户当前正在查看。我已经消除了这与 viewControllerBeforeViewController 和 viewControllerAfterViewController 在当前 viewcontroller 的 callehere 之后被调用有关的事情是我的类:

#import "APPChildViewController.h"
#import "CommentsViewController.h"

#import "ViewPhotosPagerVC.h"

@interface ViewPhotosPagerVC ()

@end

@implementation ViewPhotosPagerVC

- (void)viewDidLoad {
    [super viewDidLoad];

   // [self.navigationController setNavigationBarHidden:YES animated:YES];
    self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

    self.pageController.dataSource = self;
    [[self.pageController view] setFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];


    CommentsViewController *initialViewController = [self viewControllerAtIndex:0];
    NSDictionary *dict =[_photoArray objectAtIndex:_startingIndex];
    NSLog(@"DICT:%@",dict);
    NSString *msg_id=[dict objectForKey:@"msg_id"];
    NSLog(@"MSG_ID:%@",msg_id);
    initialViewController.msg_id=msg_id;
    initialViewController.navItem=self.navigationItem;
    initialViewController.delegate=self;

    initialViewController.theIndex=_startingIndex;
    NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];

    [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

    [self addChildViewController:self.pageController];
    [[self view] addSubview:[self.pageController view]];
    [self.pageController didMoveToParentViewController:self];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

}

- (CommentsViewController *)viewControllerAtIndex:(NSUInteger)index {


    NSLog(@"CommentVC_INDEX:%zd",index);
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    CommentsViewController *childViewController=[storyboard instantiateViewControllerWithIdentifier:@"pagerPhotoComments"];


    if(_photoArray<=index){

        index=0;
    }

    NSDictionary *dict =[_photoArray objectAtIndex:index];
    NSString *msg_id=[dict objectForKey:@"msg_id"];
    childViewController.msg_id=msg_id;
    childViewController.navItem=self.navigationItem;
    childViewController.delegate=self;
    childViewController.theIndex = index;


    return childViewController;

}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
    NSLog(@"BEFORE_PAGEVIEWCONTROL_CALLED");
    NSUInteger index = [(CommentsViewController *)viewController theIndex];

    if (index == 0) {
        NSInteger newIndex=_photoArray.count;
        newIndex--;
        return [self viewControllerAtIndex:newIndex];
    }


    // Decrease the index by 1 to return
    index--;



    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    CommentsViewController *childViewController=[storyboard instantiateViewControllerWithIdentifier:@"pagerPhotoComments"];


    if(_photoArray<=index){

        index=0;
    }

    NSDictionary *dict =[_photoArray objectAtIndex:index];
    NSString *msg_id=[dict objectForKey:@"msg_id"];
    childViewController.msg_id=msg_id;
    childViewController.delegate=self;
    childViewController.theIndex = index;

    return childViewController;

}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
    NSLog(@"AFTER_PAGEVIEWCONTROL_CALLED");

    NSUInteger index = [(CommentsViewController *)viewController theIndex];

    index++;

    if(_photoArray.count<=index){


        index=0;
    }

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    CommentsViewController *childViewController=[storyboard instantiateViewControllerWithIdentifier:@"pagerPhotoComments"];


    if(_photoArray<=index){

        index=0;
    }

    NSDictionary *dict =[_photoArray objectAtIndex:index];
    NSString *msg_id=[dict objectForKey:@"msg_id"];
    childViewController.msg_id=msg_id;
    childViewController.delegate=self;
    childViewController.theIndex = index;


    return childViewController;

}



- (void)viewWillDisappear:(BOOL)animated {


    [self.navigationController setNavigationBarHidden:NO animated:YES];

}

- (void)sharePhoto:(UIImage *)shareImage andText:(NSString *)shareText withDict:(NSDictionary *)dict{
    //NSLog(@"SHARE_IMG_UPDATE_DICT:%@",dict);

    NSString *ALBUM_ID= [dict objectForKey:@"ALBUM_ID"];
    NSString *combinedShareText;
    if(![ALBUM_ID isEqualToString:@"0"]){

        NSArray *album_array=[dict objectForKey:@"album_info"];
        NSDictionary *album_dict=[album_array objectAtIndex:0];

        //NSLog(@"ALBUM_DICT:%@",album_dict);
        NSString *album_title=[album_dict objectForKey:@"title"];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSString *first_name= [defaults objectForKey:@"first_name"];
        NSString *album_photo_count=[dict objectForKey:@"album_img_count"];


        combinedShareText= [NSString stringWithFormat:@"%@ shared a photo w. you from the event album:%@(%@ photos) ~view the rest of this album on  for IOS",first_name, album_title,album_photo_count];

        NSLog(@"SHARE_TEXT:%@",combinedShareText);

    }else{


        NSString *first_name=[dict objectForKey:@"first_name"];
        NSString *last_name=[dict objectForKey:@"last_name"];
        NSString *message =[dict objectForKey:@"message"];
        NSString *created_string=[dict objectForKey:@"created"];
        double created_double = created_string.doubleValue;
        NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:created_double];
        NSString *ago = [date timeAgo];
        combinedShareText= [NSString stringWithFormat:@"'%@'~ posted by %@ %@ %@ | You'll thank me later: www.buhz.com",message,first_name,last_name,ago];

        NSLog(@"SHARE_TEXT:%@",combinedShareText);
    }

    if(![ALBUM_ID isEqualToString:@"0"]){

    UIImage *backgroundImage = shareImage;
    UIImage *watermarkImage = [UIImage imageNamed:@"ios_watermark_logo.png"];

    UIGraphicsBeginImageContext(backgroundImage.size);
    [backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
    [watermarkImage drawInRect:CGRectMake(backgroundImage.size.width - 240, backgroundImage.size.height - 110, 230, 100)];
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();








        UIActivityViewController *controller =
        [[UIActivityViewController alloc]
         initWithActivityItems:@[combinedShareText,result]
         applicationActivities:nil];
         [self presentViewController:controller animated:YES completion:nil];
    }else{

        UIActivityViewController *controller =
        [[UIActivityViewController alloc]
         initWithActivityItems:@[combinedShareText,shareImage]
         applicationActivities:nil];
         [self presentViewController:controller animated:YES completion:nil];

    }









}







-(UIImage*) drawText:(NSString*) text
             inImage:(UIImage*)  image
             atPoint:(CGPoint)   point
{

    NSMutableAttributedString *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
    textStyle = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",text]];

    // text color
    [textStyle addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, textStyle.length)];

    // text font
    [textStyle addAttribute:NSFontAttributeName  value:[UIFont systemFontOfSize:20.0] range:NSMakeRange(0, textStyle.length)];

    UIGraphicsBeginImageContext(image.size);
    [image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];
    CGRect rect = CGRectMake(point.x, point.y, image.size.width-(point.x*2), image.size.height);
    [[UIColor whiteColor] set];

    // add text onto the image
    [textStyle drawInRect:CGRectIntegral(rect)];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;
}
- (void)shareUpdate:(NSString *)shareText withDict:(NSDictionary *)dict{

    NSLog(@"SHARE_TEXT_UPDATE_DICT:%@",dict);
    NSString *first_name=[dict objectForKey:@"first_name"];
    NSString *last_name=[dict objectForKey:@"last_name"];
    NSString *message =[dict objectForKey:@"message"];
    NSString *created_string=[dict objectForKey:@"created"];
    double created_double = created_string.doubleValue;
    NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:created_double];
    NSString *ago = [date timeAgo];
    NSString *combinedShareText= [NSString stringWithFormat:@"'%@'~ posted by %@ %@ %@ | Join me on www..com",message,first_name,last_name,ago];

    NSLog(@"SHARE_TEXT:%@",combinedShareText);

    UIActivityViewController *controller =
    [[UIActivityViewController alloc]
     initWithActivityItems:@[combinedShareText]
     applicationActivities:nil];

    [self presentViewController:controller animated:YES completion:nil];


}

@end
4

0 回答 0