2016-03-03 69 views
0

我想在圖像上添加文字。用戶可以調整該圖像上的任何位置的文字我正在使用UIRotationGestureRecognizer,UIPanGestureRecognizer,UIPinchGestureRecognizer。但問題在於,當我做手勢時,文本在我看來都在移動。我希望它移動,放大,旋轉只是該imageview。請幫忙。爲此,我在主視圖中使用了一個UIView。然後UIImageView裏面的子視圖和UITextView。ios圖像上的文字手勢

回答

0
[self buildAgreeTextViewFromString:NSLocalizedString(str,@"\UserName\xgdfg\" #<ts>#") forRow:indexPath.row]; 

- (void)buildAgreeTextViewFromString:(NSString *)localizedString forRow:(long)row 
{ 
    // 1. Split the localized string on the # sign: 
    NSArray *localizedStringPieces = [localizedString componentsSeparatedByString:@"#"]; 

    // 2. Loop through all the pieces: 
    NSUInteger msgChunkCount = localizedStringPieces ? localizedStringPieces.count : 0; 
    CGPoint wordLocation = CGPointMake(0.0, 0.0); 
    for (NSUInteger i = 0; i < msgChunkCount; i++) 
    { 
     NSString *chunk = [localizedStringPieces objectAtIndex:i]; 
     if ([chunk isEqualToString:@""]) 
     { 
      continue;  // skip this loop if the chunk is empty 
     } 

     // 3. Determine what type of word this is: 
     BOOL isTermsOfServiceLink = [chunk hasPrefix:@"<ts>"]; 
     BOOL isPrivacyPolicyLink = [chunk hasPrefix:@"<pp>"]; 
     BOOL isLink = (BOOL)(isTermsOfServiceLink || isPrivacyPolicyLink); 

     // 4. Create label, styling dependent on whether it's a link: 
     UILabel *label = [[UILabel alloc] init]; 
     label.font = [UIFont fontWithName:@"OpenSans" size:13.0F]; 
     // label.font = [UIFont systemFontOfSize:11.0f]; 
     label.text = chunk; 
     label.textColor = [UIColor yellowColor]; 
     label.userInteractionEnabled = isLink; 
     label.backgroundColor = [UIColor clearColor]; 
     label.tag = row; 

     if (isLink) 
     { 
      //label.textColor = [UIColor blueColor]; 

      //[self.view setBackgroundColor: [self colorWithHexString:@"FFFFFF"]]; 


      label.textColor = UIColorFromRGB(text1_color_hexcode); 

      //1D89FF 
      //label.highlightedTextColor = [UIColor yellowColor]; 

      // 5. Set tap gesture for this clickable text: 
      SEL selectorAction = isTermsOfServiceLink ? @selector(tapUserName:) : @selector(tapPost:); 
      UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:selectorAction]; 
      [label addGestureRecognizer:tapGesture]; 
      tapGesture.numberOfTapsRequired = 1; 
      tapGesture.delegate = self; 
      // Trim the markup characters from the label: 
      if (isTermsOfServiceLink) 
       label.text = [label.text stringByReplacingOccurrencesOfString:@"<ts>" withString:@""]; 
      if (isPrivacyPolicyLink) 
       label.text = [label.text stringByReplacingOccurrencesOfString:@"<pp>" withString:@""]; 
     } 
     else 
     { 
      label.textColor = [UIColor darkGrayColor]; 
     } 

     [label sizeToFit]; 



     if (cell.notificationTxt_view.frame.size.width < wordLocation.x + label.bounds.size.width) 
     { 
      wordLocation.x = 0.0;    // move this word all the way to the left... 
      wordLocation.y += label.frame.size.height; // ...on the next line 

      NSRange startingWhiteSpaceRange = [label.text rangeOfString:@"^\\s*" 
         options:NSRegularExpressionSearch]; 
      if (startingWhiteSpaceRange.location == 0) 
      { 
       label.text = [label.text stringByReplacingCharactersInRange:startingWhiteSpaceRange withString:@""]; 

       [label sizeToFit]; 
      } 
     } 

     //CGFloat y = (cell.notificationTxt_view.frame.size.height - label.frame.size.height)/2; 

     label.frame = CGRectMake(wordLocation.x, 
           wordLocation.y, 
           label.frame.size.width, 
           label.frame.size.height); 

     [cell.notificationTxt_view addSubview:label]; 

     wordLocation.x += label.frame.size.width; 
    } 

    NSLog(@"%ld",row); 
    if(row==[notificationArray count]-1) 
    { 
      chekScrolling=NO; 
    } 
}