- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 iOS 的新手,我面临与品牌标签相同的动画图像的问题。我正在为 UILabel 文本制作动画,为此我的代码是这样的
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
scrolllbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,scrolllbl.bounds.size.width, 1800)];
NSString *theText = @"A long string";
CGRect labelRect = CGRectMake(10, 50, 300, 50);
scrolllbl.adjustsFontSizeToFitWidth = YES;
[scrolllbl setNumberOfLines:0];
CGFloat fontSize = 30;
while (fontSize > 0.0)
{
CGSize size = [theText sizeWithFont:[UIFont fontWithName:@"Verdana" size:fontSize] constrainedToSize:CGSizeMake(labelRect.size.width, 10000) lineBreakMode:NSLineBreakByWordWrapping];
if (size.height <= labelRect.size.height) break;
fontSize -= 1.0;
}
//set font size
scrolllbl.font = [UIFont fontWithName:@"Arial" size:fontSize];
}
else
{
scrolllbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,scrolllbl.bounds.size.width, 800)];
// scrolllbl.textColor = [UIColor redColor];
}
//lbl2.text=result1;
NSLog(@"Result Array =%@",shortnamearray);
CGFloat y = 10;
NSMutableArray* animals = [NSMutableArray new];
NSUInteger maxCount = headarray.count > shortnamearray.count ? headarray.count : shortnamearray.count;
for (int i = 0; i < maxCount; i ++) {
if ([headarray objectAtIndex:i]) {
[animals addObject:[headarray objectAtIndex:i]];
}
if ([shortnamearray objectAtIndex:i]) {
[animals addObject:[shortnamearray objectAtIndex:i]];
}
}
NSLog(@"Array is =%@",animals);
for(int i=0;i<[shortnamearray count] && i<[headarray count];i++){
// y+=20;
y+=10;
NSString *newArray =[animals objectAtIndex:i];
newArray=[animals componentsJoinedByString:@""];
NSString *NewString;
[scrolllbl setLineBreakMode:NSLineBreakByWordWrapping];
scrolllbl.textAlignment = NSTextAlignmentCenter;
//[scrolllbl setText:NewString];
NSString * htmlString = @"<html><body>";
NSString *htmlString2=@"</body></html>";
NewString=[NSString stringWithFormat:@"%@%@%@",htmlString,newArray,htmlString2];
NSLog(@"New String =%@",NewString);
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[NewString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
scrolllbl.attributedText = attrStr;
NSString *theText = @"A long string";
CGRect labelRect = CGRectMake(10, 50, 300, 50);
scrolllbl.adjustsFontSizeToFitWidth = YES;
[scrolllbl setNumberOfLines:0];
CGFloat fontSize = 15;
while (fontSize > 0.0)
{
CGSize size = [theText sizeWithFont:[UIFont fontWithName:@"Verdana" size:fontSize] constrainedToSize:CGSizeMake(labelRect.size.width, 10000) lineBreakMode:NSLineBreakByWordWrapping];
if (size.height <= labelRect.size.height) break;
fontSize -= 1.0;
}
//set font size
scrolllbl.font = [UIFont fontWithName:@"Arial" size:fontSize];
}
NSTimer *timer = [NSTimer timerWithTimeInterval:1
target:self
selector:@selector(timer)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
//[_scrollView scrollRectToVisible:NSMakeRange(0,0,0.0) animated:YES];
[newsscroll addSubview:scrolllbl];
[UIView commitAnimations];
scroll.contentSize=CGSizeMake(newsscroll.frame.size.width+[shortnamearray count], scrolllbl.frame.size.height);
这就是我为 UILabel 做的。请给我建议如何为 UIImage 做。我的主要问题是图像可以根据来自网络服务的数据是多个的。提前致谢!
最佳答案
您可以使用 animateWithDuration
动画图像简单代码:
在 viewDidLoad
调用 addAllImages
:
-(void)addAllImages
{
scr=[[UIScrollView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width, 0, 320, 150)];
float xPosition=5;
for (int i =0; i<=10; i++) {
UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(xPosition, 0, 150, 150)];
img.image=[UIImage imageNamed:@"xyz.png"];
[scr addSubview:img];
xPosition+=150+5;
}
scr.frame=CGRectMake([UIScreen mainScreen].bounds.size.width, 0, xPosition, 150);
}
调用 animateImage
方法来为图像设置动画:
-(void)animateImage
{
[UIView animateWithDuration:3.0 animations:^
{
scr.frame=CGRectMake(0,0, scr.frame.size.width, scr.frame.size.height);
}
completion:^(BOOL finished)
{
scr.frame=CGRectMake([UIScreen mainScreen].bounds.size.width,0, scr.frame.size.width, scr.frame.size.height);
[self animateImage];
}];
}
关于ios - 如何在 Objective C 中像 Marquee Tag 一样为 UIImage 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41545397/
我有一个应用程序,它将在 SQLDatabase 中保存一组图像,然后用户将拍摄一张照片,我希望能够将它与数据库中的图像相匹配。 我不知道从哪里开始,有人可以帮忙吗?指出我正确的方向? 谢谢 最佳答案
在我的项目中,我有两个 UIViewController。在我的第一个 ViewController 上,我有一个 UIImageView,并且有一个来自 url 的图像。在第二个 ViewContr
如何从上下文创建 UIImage 以便我可以返回它?我只希望它有透明像素。我有一种不同的方法,可以将较小的 UIImage 添加到较大的 UIImage,但我需要从头开始。 + (UIImage *)
我想知道如何将 UIImage 居中到 UIButton。我正在使用 UIButton 的 setImage 方法来放置 UIImage .. 最佳答案 您可以使用 contentMode 属性: b
我从相机获取 UIimages 并将它们分配给要显示的 UIImageViews。当我这样做时,相机会给我一个 1200 x 1600 像素的图像,然后我将其分配给我的应用程序中的 UIImageVi
Swift 4 有 Codable这太棒了。但是UIImage默认情况下不符合它。我们怎么能做到这一点? 我试过 singleValueContainer和 unkeyedContainer exte
我的代码在普通设备上运行良好,但在视网膜设备上创建模糊图像。 有人知道我的问题的解决方案吗? + (UIImage *) imageWithView:(UIView *)view { UIGr
我总是得到:CGImageCreate:无效的图像大小:0 x 0。 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; // En
我有一张图片,想创建一张如下所示的黑色图片: 我有一个 View 和一个 ImageView ,因为它是 subview 。 ImageView 的 alpha 为 0.5,其色调颜色为黑色。 Vie
几天来我一直被困在一些必须非常简单的事情上,我已经搜索了几天,但我似乎无法找到正确的代码来工作。 我有两张图片,一张是背景图片,另一张会遮盖第一张图片。我可以用手势移动蒙版图像。我可以缩放、旋转和移动
我正在尝试拍摄类似背景透明的三角形图像,并根据用户偏好在三角形部分或背景部分上应用圆点图像。例如,我如何将圆点应用于三角形部分,然后将条纹应用于图像的透明部分。有针对这种事情的屏蔽技术吗? 非常感谢,
给出下面的图片,百分比为 25%。如何生成另一个代表给定图像径向部分 25% 的 UIImage?非常感谢任何帮助。 输入 输出 - (UIImage *)radialPortion:(float)p
这是我的代码: - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { // at this point the
我正在使用扩展程序对我的图像进行像素化处理,如下所示: func pixellated(scale: Int = 8) -> UIImage? { guard let ciImage = CI
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 6 年前。 Improve t
我有两个 UIImage 实例。我怎样才能创建第三个 UIImage 这只是拼接在一起的两个原始图像?我想要第一张图片在顶部,第二张图片在底部,这样顶部图片的底部边缘与底部图像的顶部边缘齐平。 最佳答
我有一个 UIImage 和一个 CGPoint,它们告诉我应该朝哪个方向移动它以创建另一个图像。背景可以是任何东西。 提供初始 UIImage 我如何创建新的?最有效的方法是什么? 这是我正在做的:
我有一个 UIImage,显示在 UIImageView 中。我在 UIImageView 中还有另一张图片,它位于第一张图片上方。我希望能够仅在第一张图片的边界内拖动第二张图片。为了让我的目标更清楚
我看过这个问题:UIImage Shadow Trouble 但接受的答案对我不起作用。 我想做的是获取一个 UIImage 并向其添加阴影,然后返回一个全新的 UIImage、阴影和所有内容。 这就
我有两张图片:第一张是用户个人图片,第二张是图标(角标(Badge))。 我想在第一个 uiimage(用户图像)的左下角添加第二个 uiimage(图标),并将它们保存到一个新的 Uiimage 中
我是一名优秀的程序员,十分优秀!