【iOS开发】自定义融云选取位置页面和位置信息页面的导航栏

【iOS开发】自定义融云选取位置页面和位置信息页面的导航栏

  1. 选取位置页面
    • 创建 RCLocationPickerViewController 的子类:RCDLocationViewController,可以实现自定义导航栏左右按钮
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"自定义左按钮" style:UIBarButtonItemStyleDone target:self action:@selector(leftItemDidPressed:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"自定义右按钮" style:UIBarButtonItemStyleDone target:self action:@selector(rightItemDidPressed:)];
    self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
}
- (void)leftItemDidPressed:(id)sendr {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)rightItemDidPressed:(id)sendr {
    [super rightBarButtonItemPressed:nil];
}
  • 在聊天页子类重写以下方法,并设置代理,present 到子类的对象中。

/*!
 扩展功能板的点击回调

 @param pluginBoardView 输入扩展功能板View
 @param tag             输入扩展功能(Item)的唯一标示
 */
- (void)pluginBoardView:(RCPluginBoardView *)pluginBoardView clickedItemWithTag:(NSInteger)tag {
    switch (tag) {
           case PLUGIN_BOARD_ITEM_LOCATION_TAG: {
               RCDLocationViewController *vc = [[RCDLocationViewController alloc] init];
               vc.delegate = self;
               UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc];
               [self presentViewController:navi animated:YES completion:nil];
           }
               break;

           default:
               [super pluginBoardView:pluginBoardView clickedItemWithTag:tag];
               break;
       }
}
  • 聊天页子类需要遵循代理 RCLocationPickerViewControllerDelegate,并实现方法:

    
    /*!
    地理位置选择完成之后的回调
    
    @param locationPicker 地理位置选取的ViewController
    @param location       位置的二维坐标
    @param locationName   位置的名称
    @param mapScreenShot  位置在地图中的缩略图
    
    @discussion
    如果您需要重写地理位置选择的界面,当选择地理位置完成后,需要调用此回调通知RCConversationViewController定位已完成,可以进一步生成位置消息并发送。
    */
  • (void)locationPicker:(RCLocationPickerViewController )locationPicker
    didSelectLocation:(CLLocationCoordinate2D)location
    locationName:(NSString
    )locationName
    mapScreenShot:(UIImage )mapScreenShot {
    RCLocationMessage
    locationMessage =
    [RCLocationMessage messageWithLocationImage:mapScreenShot location:location locationName:locationName];
    [self sendMessage:locationMessage pushContent:nil];
    }
2. 位置信息页面
- 创建 RCLocationViewController 的子类LocationViewController

```objective-c
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"自定义左按钮" style:UIBarButtonItemStyleDone target:self action:@selector(leftItemDidPressed:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];

    self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
}
- (void)leftItemDidPressed:(id)sendr {
    [self dismissViewControllerAnimated:YES completion:nil];
}
  • 在会话页面重写点击位置消息的回调

/**

  • 打开地理位置。开发者可以重写,自己根据经纬度打开地图显示位置。默认使用内置地图
  • @param locationMessageContent 位置消息
    */
    • (void)presentLocationViewController:(RCLocationMessage )locationMessageContent {
      // LocationViewController为 RCLocationViewController 的子类
      LocationViewController
      locationViewController = [[LocationViewController alloc] init];
      locationViewController.locationName = locationMessageContent.locationName;
      locationViewController.location = locationMessageContent.location;
      locationViewController.modalPresentationStyle = UIModalPresentationFullScreen;
      UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:locationViewController];
      navc.modalPresentationStyle = UIModalPresentationFullScreen;
      [self presentViewController:navc animated:YES completion:NULL];
      }

猜你喜欢

转载自blog.51cto.com/15056506/2678331